emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] quote the real csv separator
@ 2010-10-23 22:56 Łukasz Stelmach
  2010-10-24 16:26 ` Carsten Dominik
  0 siblings, 1 reply; 11+ messages in thread
From: Łukasz Stelmach @ 2010-10-23 22:56 UTC (permalink / raw)
  To: emacs-orgmode

Hi.

I'd rather use an optional sep argument to the org-quote-csv-field
function but I've got no idea how to stick it into the orgtbl-apply-fmt.
However, the quoting function should use current rather then assume
comma.

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/org.el b/lisp/org.el
index b482b8e..501dd8d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18019,7 +18019,7 @@ With prefix arg UNCOMPILED, load the uncompiled versions."
 
 (defun org-quote-csv-field (s)
   "Quote field for inclusion in CSV material."
-  (if (string-match "[\",]" s)
+  (if (string-match (concat "[\"" *orgtbl-sep* "]") s)
       (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
     s))
 
--8<---------------cut here---------------end--------------->8---

-- 
Miłego dnia,
Łukasz Stelmach

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] quote the real csv separator
  2010-10-23 22:56 [PATCH] quote the real csv separator Łukasz Stelmach
@ 2010-10-24 16:26 ` Carsten Dominik
  2010-10-24 16:52   ` Nick Dokos
                     ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Carsten Dominik @ 2010-10-24 16:26 UTC (permalink / raw)
  To: Łukasz Stelmach; +Cc: emacs-orgmode

Hi Lukasz,

thanks for the patch, but I do not understand it.

The separator for csv is always the comma, or am I wrong here?
So this function should use comma, hard-coded.  The only place
where it is used is when orgtbl-to-csv calls the generic
exporter.  It does so with comma as separator and with
org-quote-csv-field as formatting function.

What use case do you have in mind?

- Carsten

On Oct 24, 2010, at 12:56 AM, Łukasz Stelmach wrote:

> Hi.
>
> I'd rather use an optional sep argument to the org-quote-csv-field
> function but I've got no idea how to stick it into the orgtbl-apply- 
> fmt.
> However, the quoting function should use current rather then assume
> comma.
>
> --8<---------------cut here---------------start------------->8---
> diff --git a/lisp/org.el b/lisp/org.el
> index b482b8e..501dd8d 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -18019,7 +18019,7 @@ With prefix arg UNCOMPILED, load the  
> uncompiled versions."
>
> (defun org-quote-csv-field (s)
>   "Quote field for inclusion in CSV material."
> -  (if (string-match "[\",]" s)
> +  (if (string-match (concat "[\"" *orgtbl-sep* "]") s)
>       (concat "\"" (mapconcat 'identity (split-string s "\"")  
> "\"\"") "\"")
>     s))
>
> --8<---------------cut here---------------end--------------->8---
>
> -- 
> Miłego dnia,
> Łukasz Stelmach
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] quote the real csv separator
  2010-10-24 16:26 ` Carsten Dominik
@ 2010-10-24 16:52   ` Nick Dokos
  2010-10-24 19:37     ` Carsten Dominik
  2010-10-25 10:32     ` Stefan Vollmar
  2010-10-24 20:49   ` Łukasz Stelmach
  2010-10-25  9:15   ` Sébastien Vauban
  2 siblings, 2 replies; 11+ messages in thread
From: Nick Dokos @ 2010-10-24 16:52 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Łukasz Stelmach, nicholas.dokos, emacs-orgmode

Carsten Dominik <carsten.dominik@gmail.com> wrote:

> Hi Lukasz,
> 
> thanks for the patch, but I do not understand it.
> 
> The separator for csv is always the comma, or am I wrong here?
> So this function should use comma, hard-coded.  The only place
> where it is used is when orgtbl-to-csv calls the generic
> exporter.  It does so with comma as separator and with
> org-quote-csv-field as formatting function.
> 
> What use case do you have in mind?
> 
> - Carsten
> 

[This is *not* a comment on the patch itself, which I have not looked at
carefully.]

CSV started out simple and grew to be a monster (but it is still useful
despite all that). It's not formally defined, so there are several
variations, dialects and subdialects.  Here e.g. is the description of
the python module that handles CSV: it defines an "excel" dialect and an
"excel_tab" subdialect, the latter using a TAB as a delimiter. If you
want more details and have python installed, start it up, import csv and
then say "help(csv)".

HTH,
Nick

,----
| NAME
|     csv - CSV parsing and writing.
| 
| FILE
|     /usr/lib/python2.5/csv.py
| 
| MODULE DOCS
|     http://www.python.org/doc/current/lib/module-csv.html
| 
| DESCRIPTION
|     This module provides classes that assist in the reading and writing
|     of Comma Separated Value (CSV) files, and implements the interface
|     described by PEP 305.  Although many CSV files are simple to parse,
|     the format is not formally defined by a stable specification and
|     is subtle enough that parsing lines of a CSV file with something
|     like line.split(",") is bound to fail.  The module supports three
|     basic APIs: reading, writing, and registration of dialects.
|     
|     
|     DIALECT REGISTRATION:
|     
|     Readers and writers support a dialect argument, which is a convenient
|     handle on a group of settings.  When the dialect argument is a string,
|     it identifies one of the dialects previously registered with the module.
|     If it is a class or instance, the attributes of the argument are used as
|     the settings for the reader or writer:
|     
|         class excel:
|             delimiter = ','
|             quotechar = '"'
|             escapechar = None
|             doublequote = True
|             skipinitialspace = False
|             lineterminator = '\r\n'
|             quoting = QUOTE_MINIMAL
|     
|     SETTINGS:
|     
|         * quotechar - specifies a one-character string to use as the 
|             quoting character.  It defaults to '"'.
|         * delimiter - specifies a one-character string to use as the 
|             field separator.  It defaults to ','.
|         * skipinitialspace - specifies how to interpret whitespace which
|             immediately follows a delimiter.  It defaults to False, which
|             means that whitespace immediately following a delimiter is part
|             of the following field.
|         * lineterminator -  specifies the character sequence which should 
|             terminate rows.
|         * quoting - controls when quotes should be generated by the writer.
|             It can take on any of the following module constants:
|     
|             csv.QUOTE_MINIMAL means only when required, for example, when a
|                 field contains either the quotechar or the delimiter
|             csv.QUOTE_ALL means that quotes are always placed around fields.
|             csv.QUOTE_NONNUMERIC means that quotes are always placed around
|                 fields which do not parse as integers or floating point
|                 numbers.
|             csv.QUOTE_NONE means that quotes are never placed around fields.
|         * escapechar - specifies a one-character string used to escape 
|             the delimiter when quoting is set to QUOTE_NONE.
|         * doublequote - controls the handling of quotes inside fields.  When
|             True, two consecutive quotes are interpreted as one during read,
|             and when writing, each quote character embedded in the data is
|             written as two quotes
`----

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] quote the real csv separator
  2010-10-24 16:52   ` Nick Dokos
@ 2010-10-24 19:37     ` Carsten Dominik
  2010-10-25 10:32     ` Stefan Vollmar
  1 sibling, 0 replies; 11+ messages in thread
From: Carsten Dominik @ 2010-10-24 19:37 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: Łukasz Stelmach, emacs-orgmode


On Oct 24, 2010, at 6:52 PM, Nick Dokos wrote:

> Carsten Dominik <carsten.dominik@gmail.com> wrote:
>
>> Hi Lukasz,
>>
>> thanks for the patch, but I do not understand it.
>>
>> The separator for csv is always the comma, or am I wrong here?
>> So this function should use comma, hard-coded.  The only place
>> where it is used is when orgtbl-to-csv calls the generic
>> exporter.  It does so with comma as separator and with
>> org-quote-csv-field as formatting function.
>>
>> What use case do you have in mind?
>>
>> - Carsten
>>
>
> [This is *not* a comment on the patch itself, which I have not  
> looked at
> carefully.]
>
> CSV started out simple and grew to be a monster (but it is still  
> useful
> despite all that). It's not formally defined, so there are several
> variations, dialects and subdialects.  Here e.g. is the description of
> the python module that handles CSV: it defines an "excel" dialect  
> and an
> "excel_tab" subdialect, the latter using a TAB as a delimiter. If you
> want more details and have python installed, start it up, import csv  
> and
> then say "help(csv)".

Thanks for this, useful info.  I remember when we implemented csv that
it seemed trivial and was not.

Org-mode does have a separate orgtbl-to-tsv which
handles tab-separated data.

>
> HTH,
> Nick
>
> ,----
> | NAME
> |     csv - CSV parsing and writing.
> |
> | FILE
> |     /usr/lib/python2.5/csv.py
> |
> | MODULE DOCS
> |     http://www.python.org/doc/current/lib/module-csv.html
> |
> | DESCRIPTION
> |     This module provides classes that assist in the reading and  
> writing
> |     of Comma Separated Value (CSV) files, and implements the  
> interface
> |     described by PEP 305.  Although many CSV files are simple to  
> parse,
> |     the format is not formally defined by a stable specification and
> |     is subtle enough that parsing lines of a CSV file with something
> |     like line.split(",") is bound to fail.  The module supports  
> three
> |     basic APIs: reading, writing, and registration of dialects.
> |
> |
> |     DIALECT REGISTRATION:
> |
> |     Readers and writers support a dialect argument, which is a  
> convenient
> |     handle on a group of settings.  When the dialect argument is a  
> string,
> |     it identifies one of the dialects previously registered with  
> the module.
> |     If it is a class or instance, the attributes of the argument  
> are used as
> |     the settings for the reader or writer:
> |
> |         class excel:
> |             delimiter = ','
> |             quotechar = '"'
> |             escapechar = None
> |             doublequote = True
> |             skipinitialspace = False
> |             lineterminator = '\r\n'
> |             quoting = QUOTE_MINIMAL
> |
> |     SETTINGS:
> |
> |         * quotechar - specifies a one-character string to use as the
> |             quoting character.  It defaults to '"'.
> |         * delimiter - specifies a one-character string to use as the
> |             field separator.  It defaults to ','.
> |         * skipinitialspace - specifies how to interpret whitespace  
> which
> |             immediately follows a delimiter.  It defaults to  
> False, which
> |             means that whitespace immediately following a  
> delimiter is part
> |             of the following field.
> |         * lineterminator -  specifies the character sequence which  
> should
> |             terminate rows.
> |         * quoting - controls when quotes should be generated by  
> the writer.
> |             It can take on any of the following module constants:
> |
> |             csv.QUOTE_MINIMAL means only when required, for  
> example, when a
> |                 field contains either the quotechar or the delimiter
> |             csv.QUOTE_ALL means that quotes are always placed  
> around fields.
> |             csv.QUOTE_NONNUMERIC means that quotes are always  
> placed around
> |                 fields which do not parse as integers or floating  
> point
> |                 numbers.
> |             csv.QUOTE_NONE means that quotes are never placed  
> around fields.
> |         * escapechar - specifies a one-character string used to  
> escape
> |             the delimiter when quoting is set to QUOTE_NONE.
> |         * doublequote - controls the handling of quotes inside  
> fields.  When
> |             True, two consecutive quotes are interpreted as one  
> during read,
> |             and when writing, each quote character embedded in the  
> data is
> |             written as two quotes
> `----

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] quote the real csv separator
  2010-10-24 16:26 ` Carsten Dominik
  2010-10-24 16:52   ` Nick Dokos
@ 2010-10-24 20:49   ` Łukasz Stelmach
  2010-10-25  1:25     ` Bernt Hansen
  2010-10-25  9:15   ` Sébastien Vauban
  2 siblings, 1 reply; 11+ messages in thread
From: Łukasz Stelmach @ 2010-10-24 20:49 UTC (permalink / raw)
  To: emacs-orgmode

Carsten Dominik <carsten.dominik@gmail.com> writes:

> On Oct 24, 2010, at 12:56 AM, Łukasz Stelmach wrote:
>
>> I'd rather use an optional sep argument to the org-quote-csv-field
>> function but I've got no idea how to stick it into the orgtbl-apply-
>> fmt. However, the quoting function should use current rather then
>> assume comma.
>>
[...]
>>
> thanks for the patch, but I do not understand it.
>
> The separator for csv is always the comma, or am I wrong here?

A bit. The fact is that both OpenOffice (i've just checked) and
Microsoft Office (I am almost 100% sure) allow to choose the separator
upon export. And org-mode also allows it with radio tables with the :sep
parameter (which is passed to the generic exporter).

> So this function should use comma, hard-coded.  The only place
> where it is used is when orgtbl-to-csv calls the generic
> exporter.  It does so with comma as separator and with
> org-quote-csv-field as formatting function.
>
> What use case do you have in mind?

For me in particular? This is quite complicated ;-) And if you decide to
reject the patch I will understand. (Read only I you have some time to
waste ;)

My bank lets me download monthly reports as CSV. In fact they let me
choose the separator and the default value is the comma. But I choose
'|' because then I can open the csv as org file and just do

(replace-regexp "^" "|")

to get a beautiful org-mode table.

The reports from the bank are prepared for each account independently.
When I transfer money between them I get entries in two reports. To get
rid of this mess I decided to write a perl programme and I do it. And I
prepare test data as radio tables and export them using pipe (yeah I
know, this doesn't make a good point in favour of my patch) because...
I prefer to manipulate all my bank report data with org-mode as tables.

*My* use case isn't very good, is it?

-- 
Miłego dnia,
Łukasz Stelmach

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] quote the real csv separator
  2010-10-24 20:49   ` Łukasz Stelmach
@ 2010-10-25  1:25     ` Bernt Hansen
  2010-10-25  8:45       ` Łukasz Stelmach
  0 siblings, 1 reply; 11+ messages in thread
From: Bernt Hansen @ 2010-10-25  1:25 UTC (permalink / raw)
  To: Łukasz Stelmach; +Cc: emacs-orgmode

Łukasz Stelmach <lukasz.stelmach@iem.pw.edu.pl> writes:

> Carsten Dominik <carsten.dominik@gmail.com> writes:
>
>> On Oct 24, 2010, at 12:56 AM, Łukasz Stelmach wrote:
>>
>>> I'd rather use an optional sep argument to the org-quote-csv-field
>>> function but I've got no idea how to stick it into the orgtbl-apply-
>>> fmt. However, the quoting function should use current rather then
>>> assume comma.
>>>
> [...]
>>>
>> thanks for the patch, but I do not understand it.
>>
>> The separator for csv is always the comma, or am I wrong here?
>
> A bit. The fact is that both OpenOffice (i've just checked) and
> Microsoft Office (I am almost 100% sure) allow to choose the separator
> upon export. And org-mode also allows it with radio tables with the :sep
> parameter (which is passed to the generic exporter).
>
>> So this function should use comma, hard-coded.  The only place
>> where it is used is when orgtbl-to-csv calls the generic
>> exporter.  It does so with comma as separator and with
>> org-quote-csv-field as formatting function.
>>
>> What use case do you have in mind?
>
> For me in particular? This is quite complicated ;-) And if you decide to
> reject the patch I will understand. (Read only I you have some time to
> waste ;)
>
> My bank lets me download monthly reports as CSV. In fact they let me
> choose the separator and the default value is the comma. But I choose
> '|' because then I can open the csv as org file and just do
>
> (replace-regexp "^" "|")
>
> to get a beautiful org-mode table.

There is an easier org-mode way I think.  Just get the comma delimited
data into your org file, select the region and C-c | to get your table.

If you are inserting an external file with C-x i <file> RET
then C-x C-x marks the region and C-c | converts it to a table.

If this works better for you then I would suggest dropping the patch.

Regards,
Bernt

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] quote the real csv separator
  2010-10-25  1:25     ` Bernt Hansen
@ 2010-10-25  8:45       ` Łukasz Stelmach
  2010-10-25  9:06         ` Carsten Dominik
  0 siblings, 1 reply; 11+ messages in thread
From: Łukasz Stelmach @ 2010-10-25  8:45 UTC (permalink / raw)
  To: emacs-orgmode

Bernt Hansen <bernt@norang.ca> writes:

> Łukasz Stelmach <lukasz.stelmach@iem.pw.edu.pl> writes:
>> Carsten Dominik <carsten.dominik@gmail.com> writes:
>>> What use case do you have in mind?
[...]
>> My bank lets me download monthly reports as CSV. In fact they let me
>> choose the separator and the default value is the comma. But I choose
>> '|' because then I can open the csv as org file and just do
>>
>> (replace-regexp "^" "|")
>>
>> to get a beautiful org-mode table.
>
> There is an easier org-mode way I think.  Just get the comma delimited
> data into your org file, select the region and C-c | to get your table.
>
> If you are inserting an external file with C-x i <file> RET
> then C-x C-x marks the region and C-c | converts it to a table.

Cool :-) It works like charm. I'll have to check how to convert decimal
commas to periods. I still like '|' more for my perl script, though,
because it's enough to split '\|' and not care about quoted commas. But
this is my problem.

OK, I won't insist on keeping the patch but I would like to get a
rationale of :sep parameter in orgtbl-to-generic without a choice of how
to quote it. OR, if you think that CSV should stay as it is then I
suggest such a rewrite:

(defun orgtbl-to-csv (table params)
  (orgtbl-to-generic table (org-combine-plists
                            params
			    '(:sep "," :fmt org-quote-csv-field))))

to make CSV :sep and and :fmt mandatory (that's how this all have starded).

-- 
Miłego dnia,
Łukasz Stelmach

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Re: [PATCH] quote the real csv separator
  2010-10-25  8:45       ` Łukasz Stelmach
@ 2010-10-25  9:06         ` Carsten Dominik
  2010-10-25 11:59           ` Łukasz Stelmach
  0 siblings, 1 reply; 11+ messages in thread
From: Carsten Dominik @ 2010-10-25  9:06 UTC (permalink / raw)
  To: Łukasz Stelmach; +Cc: emacs-orgmode


On Oct 25, 2010, at 10:45 AM, Łukasz Stelmach wrote:

> Bernt Hansen <bernt@norang.ca> writes:
>
>> Łukasz Stelmach <lukasz.stelmach@iem.pw.edu.pl> writes:
>>> Carsten Dominik <carsten.dominik@gmail.com> writes:
>>>> What use case do you have in mind?
> [...]
>>> My bank lets me download monthly reports as CSV. In fact they let me
>>> choose the separator and the default value is the comma. But I  
>>> choose
>>> '|' because then I can open the csv as org file and just do
>>>
>>> (replace-regexp "^" "|")
>>>
>>> to get a beautiful org-mode table.
>>
>> There is an easier org-mode way I think.  Just get the comma  
>> delimited
>> data into your org file, select the region and C-c | to get your  
>> table.
>>
>> If you are inserting an external file with C-x i <file> RET
>> then C-x C-x marks the region and C-c | converts it to a table.
>
> Cool :-) It works like charm. I'll have to check how to convert  
> decimal
> commas to periods. I still like '|' more for my perl script, though,
> because it's enough to split '\|' and not care about quoted commas.  
> But
> this is my problem.
>
> OK, I won't insist on keeping the patch but I would like to get a
> rationale of :sep parameter in orgtbl-to-generic without a choice of  
> how
> to quote it.

orgtbl-to-generic is, well, very generic.  It is up to the caller that  
when she/he specified :sep, to ensure the the separator does not show  
up in fields, of to specify :fmt in a way that it will take care of  
any necessary quoting.  There is no generic way of quoting, sometimes  
it is prepending a character, bu in other cases something completely  
different might be needed.

> OR, if you think that CSV should stay as it is then I
> suggest such a rewrite:
>
> (defun orgtbl-to-csv (table params)
>  (orgtbl-to-generic table (org-combine-plists
>                            params
> 			    '(:sep "," :fmt org-quote-csv-field))))
>
> to make CSV :sep and and :fmt mandatory (that's how this all have  
> starded).

I don't understand, here is the current definition of orgtbl-to-csv:

(defun orgtbl-to-csv (table params)
   "Convert the orgtbl-mode table to CSV material.
This does take care of the proper quoting of fields with comma or  
quotes."
   (orgtbl-to-generic table (org-combine-plists
			    '(:sep "," :fmt org-quote-csv-field)
			    params)))

so these are mandatory.  I guess I do not understand what you are  
saying.

Best wishes

- Carsten

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] quote the real csv separator
  2010-10-24 16:26 ` Carsten Dominik
  2010-10-24 16:52   ` Nick Dokos
  2010-10-24 20:49   ` Łukasz Stelmach
@ 2010-10-25  9:15   ` Sébastien Vauban
  2 siblings, 0 replies; 11+ messages in thread
From: Sébastien Vauban @ 2010-10-25  9:15 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi all,

Carsten Dominik wrote:
> Hi Lukasz,
>
> thanks for the patch, but I do not understand it.
>
> The separator for csv is always the comma, or am I wrong here?
> So this function should use comma, hard-coded.

Just to confirm what has been implictly shown by Nick, the separator can be
many things, and is not limited to comma and tab.

By default, on a Windows with French locale settings, the separator is the
semi-colon... certainly because the comma is used as decimal separator.

Best regards,
  Seb

-- 
Sébastien Vauban


_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] quote the real csv separator
  2010-10-24 16:52   ` Nick Dokos
  2010-10-24 19:37     ` Carsten Dominik
@ 2010-10-25 10:32     ` Stefan Vollmar
  1 sibling, 0 replies; 11+ messages in thread
From: Stefan Vollmar @ 2010-10-25 10:32 UTC (permalink / raw)
  To: emacs-orgmode Mailinglist; +Cc: nicholas.dokos


[-- Attachment #1.1: Type: text/plain, Size: 5692 bytes --]

Dear Carsten,
dear Nick,

if you are using a standard German locale on either Windows or MacOS, MS Excel will use semicolons instead of commas as separators when saving in CSV format - so, really, it is "semicolon separated value" by default for MS products - the wisdom of this approach is questionable (and one of the many quirks you encounter when using Excel in a scientific setting with a traditional mix of several locales). The reasoning, presumably, is that the German number format uses "," as decimal separator and conflicts with also using commas to separate columns. You can simulate this by switching your operating system to international settings: German (Excel needs to be restarted to reflect these changes).

Warm regards,
 Stefan

On 24.10.2010, at 18:52, Nick Dokos wrote:

> Carsten Dominik <carsten.dominik@gmail.com> wrote:
> 
>> Hi Lukasz,
>> 
>> thanks for the patch, but I do not understand it.
>> 
>> The separator for csv is always the comma, or am I wrong here?
>> So this function should use comma, hard-coded.  The only place
>> where it is used is when orgtbl-to-csv calls the generic
>> exporter.  It does so with comma as separator and with
>> org-quote-csv-field as formatting function.
>> 
>> What use case do you have in mind?
>> 
>> - Carsten
>> 
> 
> [This is *not* a comment on the patch itself, which I have not looked at
> carefully.]
> 
> CSV started out simple and grew to be a monster (but it is still useful
> despite all that). It's not formally defined, so there are several
> variations, dialects and subdialects.  Here e.g. is the description of
> the python module that handles CSV: it defines an "excel" dialect and an
> "excel_tab" subdialect, the latter using a TAB as a delimiter. If you
> want more details and have python installed, start it up, import csv and
> then say "help(csv)".
> 
> HTH,
> Nick
> 
> ,----
> | NAME
> |     csv - CSV parsing and writing.
> | 
> | FILE
> |     /usr/lib/python2.5/csv.py
> | 
> | MODULE DOCS
> |     http://www.python.org/doc/current/lib/module-csv.html
> | 
> | DESCRIPTION
> |     This module provides classes that assist in the reading and writing
> |     of Comma Separated Value (CSV) files, and implements the interface
> |     described by PEP 305.  Although many CSV files are simple to parse,
> |     the format is not formally defined by a stable specification and
> |     is subtle enough that parsing lines of a CSV file with something
> |     like line.split(",") is bound to fail.  The module supports three
> |     basic APIs: reading, writing, and registration of dialects.
> |     
> |     
> |     DIALECT REGISTRATION:
> |     
> |     Readers and writers support a dialect argument, which is a convenient
> |     handle on a group of settings.  When the dialect argument is a string,
> |     it identifies one of the dialects previously registered with the module.
> |     If it is a class or instance, the attributes of the argument are used as
> |     the settings for the reader or writer:
> |     
> |         class excel:
> |             delimiter = ','
> |             quotechar = '"'
> |             escapechar = None
> |             doublequote = True
> |             skipinitialspace = False
> |             lineterminator = '\r\n'
> |             quoting = QUOTE_MINIMAL
> |     
> |     SETTINGS:
> |     
> |         * quotechar - specifies a one-character string to use as the 
> |             quoting character.  It defaults to '"'.
> |         * delimiter - specifies a one-character string to use as the 
> |             field separator.  It defaults to ','.
> |         * skipinitialspace - specifies how to interpret whitespace which
> |             immediately follows a delimiter.  It defaults to False, which
> |             means that whitespace immediately following a delimiter is part
> |             of the following field.
> |         * lineterminator -  specifies the character sequence which should 
> |             terminate rows.
> |         * quoting - controls when quotes should be generated by the writer.
> |             It can take on any of the following module constants:
> |     
> |             csv.QUOTE_MINIMAL means only when required, for example, when a
> |                 field contains either the quotechar or the delimiter
> |             csv.QUOTE_ALL means that quotes are always placed around fields.
> |             csv.QUOTE_NONNUMERIC means that quotes are always placed around
> |                 fields which do not parse as integers or floating point
> |                 numbers.
> |             csv.QUOTE_NONE means that quotes are never placed around fields.
> |         * escapechar - specifies a one-character string used to escape 
> |             the delimiter when quoting is set to QUOTE_NONE.
> |         * doublequote - controls the handling of quotes inside fields.  When
> |             True, two consecutive quotes are interpreted as one during read,
> |             and when writing, each quote character embedded in the data is
> |             written as two quotes
> `----
> 
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

-- 
Dr. Stefan Vollmar, Dipl.-Phys.
Head of IT group
Max-Planck-Institut für neurologische Forschung
Gleuelerstr. 50, 50931 Köln, Germany
Tel.: +49-221-4726-213  FAX +49-221-4726-298
Tel.: +49-221-478-5713  Mobile: 0160-93874279
E-Mail: vollmar@nf.mpg.de   http://www.nf.mpg.de








[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 4409 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] quote the real csv separator
  2010-10-25  9:06         ` Carsten Dominik
@ 2010-10-25 11:59           ` Łukasz Stelmach
  0 siblings, 0 replies; 11+ messages in thread
From: Łukasz Stelmach @ 2010-10-25 11:59 UTC (permalink / raw)
  To: emacs-orgmode

Carsten Dominik <carsten.dominik@gmail.com> writes:

> On Oct 25, 2010, at 10:45 AM, Łukasz Stelmach wrote:
>> OR, if you think that CSV should stay as it is then I
>> suggest such a rewrite:
>>
>> (defun orgtbl-to-csv (table params)
>>  (orgtbl-to-generic table (org-combine-plists
>>                            params
>> 			    '(:sep "," :fmt org-quote-csv-field))))
>>
>> to make CSV :sep and and :fmt mandatory (that's how this all have
>> starded).
>
> I don't understand, here is the current definition of orgtbl-to-csv:
>
> (defun orgtbl-to-csv (table params)
>   "Convert the orgtbl-mode table to CSV material.
> This does take care of the proper quoting of fields with comma or
> quotes."
>   (orgtbl-to-generic table (org-combine-plists
> 			    '(:sep "," :fmt org-quote-csv-field)
> 			    params)))
>
> so these are mandatory.  I guess I do not understand what you are
> saying.

OK, try to eval these:

(let ((params '(:sep "|")))
  (org-combine-plists
    '(:sep "," :fmt org-quote-csv-field)
    params))

(let ((params '(:sep "|")))
  (org-combine-plists
    params
    '(:sep "," :fmt org-quote-csv-field)))

The latter prevents :sep from being overriden.

-- 
Miłego dnia,
Łukasz Stelmach

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-10-25 12:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-23 22:56 [PATCH] quote the real csv separator Łukasz Stelmach
2010-10-24 16:26 ` Carsten Dominik
2010-10-24 16:52   ` Nick Dokos
2010-10-24 19:37     ` Carsten Dominik
2010-10-25 10:32     ` Stefan Vollmar
2010-10-24 20:49   ` Łukasz Stelmach
2010-10-25  1:25     ` Bernt Hansen
2010-10-25  8:45       ` Łukasz Stelmach
2010-10-25  9:06         ` Carsten Dominik
2010-10-25 11:59           ` Łukasz Stelmach
2010-10-25  9:15   ` Sébastien Vauban

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).