how can i change the text delimiter

Amit Khemka khemkaamit at gmail.com
Thu Aug 31 04:51:34 EDT 2006


On 31 Aug 2006 00:25:38 -0700, sonald <sonaldgr8 at gmail.com> wrote:
> Hi,
> I am using
> Python version python-2.4.1 and along with this there are other
> installables
> like:
> 1. fastcsv-1.0.1.win32-py2.4.exe
> 2. psyco-1.4.win32-py2.4.exe
> 3. scite-1.63-setup.exe
>
> We are freshers here, joined new... and are now into handling this
> module which validates the data files, which are provided in some
> predefined format from the third party.
> The data files are provided in the comma separated format.
>
> The fastcsv package is imported in the code...
>      import fastcsv
> and
>      csv = fastcsv.parser(strict = 1,field_sep = ',')
>
> can u plz tell me where to find the parser function definition, (used
> above)
> so that if possible i can provide a parameter for
> text qualifier or text separator or text delimiter..
> just as {field_sep = ','} (as given above)
>
> I want to handle string containing double quotes (")
> but the problem is that the default text qualifier is double quote
>
> Now if I can change the default text qualifier... to say pipe (|)
> the double quote inside the string may be ignored...
> plz refer to the example given in my previous query...
>
> Thanks..

As Fredrik and Skip mentioned earlier, The csv(from
www.object-craft.com.au/projects/csv/) module you are using is
obsolete. And an improved version is a part of standard python
distribution. You should the standard module, in the way as suggested.

You may like to do the following.
1. Convert all your data-file with say '|' as the quotechar (text delimiter)
2. Use (Import) the *standard* python cvs module ()

A sample code would look like:

import csv     # standard csv module distributed with python

inputFile = "csv_file_with_pipe_as_quotchar.txt"
reader = csv.reader(open(inputFile), quotechar='|')

for row in reader:
     # do what ever you would like to do

cheers,
amit.

----
Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.



More information about the Python-list mailing list