I will read this when I get a minute, but I must say thanks for the explanation.
tutor@python really is the most helpful mailing list EVER!
> Date: Tue, 24 Jun 2014 00:54:30 +1000
> From: st...@pearwood.info
> To: tutor@python.org
> Subject: Re: [Tutor] write dictionary to file
On Mon, Jun 23, 2014 at 09:17:44AM +, Ian D wrote:
> > for row in spamreader:
> > if row['year'] == '40':
> > email = row['user'] + '@email.com'
> > output = [ row[fieldname] for fieldname in fields ]
>
> I am unsure about this syntax [ row[fieldname] for fieldname in fiel
> To: tutor@python.org
> Date: Mon, 23 Jun 2014 09:17:44 +
> Subject: Re: [Tutor] write dictionary to file
>
>
>>>
>>> import csv
>>>
>>> csvfile= open('StudentListToSort.csv', newline='')
>>> spamreader = csv.Dict
Ian, take a step back; the first step to solve a problem is to state it
clearly. You want to write a dict to a file.
(1) What would the dictionary look like? Give concrete example, e. g.
{"foo": 42, "bar": 'that\'s not "funny"'}
(2) What should the resulting file look like when you open it in a
>>
>> import csv
>>
>> csvfile= open('StudentListToSort.csv', newline='')
>> spamreader = csv.DictReader(csvfile,delimiter=',',quotechar='|')
>
> Are you sure that your input file uses | as a quote character and , as
> the field delimiter?
No I overlooked this
>
>
>> #open a file to write to l
Thanks a lot this is really helpful as have been the other posts.
>
> Have you tried reading the documentation? It sounds like you're just
> throwing random bits of code at it and hoping something works.
>
> A better approach is to slow down and try to understand what the csv is
> doing, what it
On Fri, Jun 20, 2014 at 08:38:52AM +, Ian D wrote:
> This is driving me nuts.
>
> I have tried many different things, but I just do not understand this
> csv library.
Have you tried reading the documentation? It sounds like you're just
throwing random bits of code at it and hoping something
Hi,
You've had a very good reply from Mark already however I want to add
to it and further clarify what he pointed out (why exactly *are* you
getting the tuple error after all?), also I've updated the prior
example to help explain, see below:
On 20 June 2014 15:11, Ian D wrote:
>
> import csv
>
On 20/06/2014 15:11, Ian D wrote:
Ok making some progress by changing the 'wb' to 'w'
err no.
unstuck again.
import csv
csvfile= open('StudentListToSort.csv', newline='')
spamreader = csv.reader(csvfile,delimiter=',',quotechar='|')
outfile = open('outfile.csv','w')
for row in spamreader
>
> Ok making some progress by changing the 'wb' to 'w'
>
err no.
unstuck again.
import csv
csvfile= open('StudentListToSort.csv', newline='')
spamreader = csv.reader(csvfile,delimiter=',',quotechar='|')
outfile = open('outfile.csv','w')
for row in spamreader:
if row[4] == '6':
Ok making some progress by changing the 'wb' to 'w'
>
> Ok I see this error and the example shows a different type of syntax.
>
>
> Rather than a file open for writing:
>
> outfile = open('output.csv', 'wb')
>
>
> it uses
>
> with open('data.csv', 'w', newline='') as out:
>
>
>
> now is this writ
Thanks
>
> Nonetheless, having re-read your question and having googled a bit, it
> seems that your problem might be related to Python 2 vs. Python 3, see
> here:
> http://stackoverflow.com/questions/24294457/python-typeerror-str-does-not-support-the-buffer-interface
>
> In short: In Python 2 you
Hi,
Firstly an apology -- I only just noticed your original code was
Python 3 -- my example was Python 2, so there would be some changes
required to make the example work on Python 3...
On 20 June 2014 11:19, Ian D wrote:
> Thanks for your help
>
>
> I am not much closer in understanding this so
Thanks for your help
I am not much closer in understanding this so I am going to try and start with
a simpler example for myself.
I will try and write some values to a file as I am struggling even doing this.
TypeError: 'str' does not support the buffer interface
TypeError: 'tuple' does not
Hi,
On 20 June 2014 09:38, Ian D wrote:
> #so far this should read a file
> #using dictreader and take a column and join some text onto it
>
> import csv
>
> csvfile= open('StudentListToSort.csv', newline='')
> spamreader = csv.DictReader(csvfile,delimiter=',',quotechar='|')
>
> #open a file to w
This is driving me nuts.
I have tried many different things, but I just do not understand this csv
library.
I have tried passing various parameters to the writerow method and I am really
getting nowhere fast.
I just want to read from a file, join text to column and write to file.
The wr
On Thu, Jun 19, 2014 at 8:13 AM, Ian D wrote:
> When trying to write my dictionary to a file I get:
>
>
> f.write(output)
> TypeError: 'tuple' does not support the buffer interface
When writing structured data to disk files, you need to do something
extra, because what disk files support are the
When trying to write my dictionary to a file I get:
f.write(output)
TypeError: 'tuple' does not support the buffer interface
using this example:
#so far this should read a file
#using dictreader and take a column and join some text onto it
import csv
csvfile= open('StudentListToSort.csv
18 matches
Mail list logo