[Tutor] get columns from txt file

Joel Goldstick joel.goldstick at gmail.com
Fri Jul 13 14:44:55 CEST 2012


On Fri, Jul 13, 2012 at 5:21 AM, Marc Tompkins <marc.tompkins at gmail.com> wrote:
> Reply to the group, please!
>
> On Fri, Jul 13, 2012 at 2:09 AM, susana moreno colomer
> <susana_87 at hotmail.com> wrote:
>>
>>
>> Hi!
>> I am sorry, but still I don't get it!
>> I am trying with this (the code is attached)
>>
>> csv_out=csv.writer(open('out1.csv', 'wb'), delimiter=' ',
>> quoting=csv.QUOTE_ALL, dialect='excel')
>> and
>> csv_out=csv.writer(open('out1.csv', 'wb'), dialect='excel-tab')
>>
You need to refer to the spec:  csv.writer(csvfile[,
dialect='excel'][, fmtparam])
(http://docs.python.org/library/csv.html#csv.writer)

so i would use:
    csv_out = csv.writer(open('out1.csv', 'wb'), dialect='excel')

This will give you output separated by commas and (if I am not
mistaken) is will only quote values that are strings.


>> When I open out1 with text editor, I get 6 columns, but when I open it
>> with excel I get one column (6 numbers on each cell, how can I separate it
>> it???)
>>
>> The files from wich I get the columns are txt files.
>>
>> Many thanks!!
>
>
> It sounds more like an Excel import problem than a Python output problem at
> this point, but it's hard to tell.
>
> Is the data you're dealing with private/confidential?  If not, could you
> attach your output CSV file?  A quick look could take the place of hours of
> guesswork.
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
I agree with Marc's comments.  I would use the comma separated value
version of the output file, not the tabbed version.

So if your file looks like this in a text editor:

1,2,3,4,5,6

it will put each value in successive columns.


-- 
Joel Goldstick


More information about the Tutor mailing list