Re: [Tutor] write dictionary to file

2014-06-20 Thread Ian D
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

Re: [Tutor] write dictionary to file

2014-06-20 Thread Walter Prins
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

Re: [Tutor] write dictionary to file

2014-06-20 Thread Ian D
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

Re: [Tutor] write dictionary to file

2014-06-20 Thread Walter Prins
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

Re: [Tutor] write dictionary to file

2014-06-20 Thread Ian D
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

Re: [Tutor] write dictionary to file

2014-06-20 Thread Ian D
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

Re: [Tutor] write dictionary to file

2014-06-20 Thread Ian D
> > 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':

Re: [Tutor] write dictionary to file

2014-06-20 Thread Mark Lawrence
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

Re: [Tutor] write dictionary to file

2014-06-20 Thread Walter Prins
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 >

[Tutor] Fwd: Re: Tips

2014-06-20 Thread Alex Kleider
On 2014-06-19 15:52, Steven D'Aprano wrote: On Thu, Jun 19, 2014 at 11:10:26AM -0700, Alex Kleider wrote: The idea of a singleton class is new to me as is this comparison of class vs module. Can anyone suggest a place to turn for more discussion of the topic? thks, alexK "Singleton" is one o

Re: [Tutor] write dictionary to file

2014-06-20 Thread Steven D'Aprano
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