Thanks for the answer Dima,
I tried this:
-----
import csv
o=open('test.csv','wb')
output=csv.writer(o)
data=[[1,2],[3,4],[5,6]]
for r in data:
output.writerow(r)
o.close()
----
I'm afraid that that doesn't work either (still output an empty csv file).
Note that I have never had to use the close statement when running in
python or bash mode so I can only assume that it's an issue with the
notebook...
Vince
On 25 March 2012 12:26, Dima Pasechnik <[email protected]> wrote:
>
>
> On Sunday, 25 March 2012 18:21:23 UTC+8, Vincent Knight wrote:
>
>> Hi all,
>>
>> I've had trouble with this for a while.
>>
>> If I write the following in to a notebook cell:
>>
>> ------
>> import csv
>>
>> output=csv.writer(open('test.csv','wb'))
>>
>> data=[[1,2],[3,4],[5,6]]
>>
>> for r in data:
>> output.writerow(r)
>>
>> -----
>>
>
> Perhaps you should close() what what was open() ? I.e.
>
> o= open('test.csv','wb')
> output=csv.writer(o)
> # do the stuff....
> o.close()
>
>
>
>>
>> and evaluate, a hyperlink appears entitled 'test.csv', if I open that csv
>> file it is empy. Checking the code in bash mode in sage (and python) does
>> however work (and create the required csv file).
>>
>> Am I missing something to do with the notebook?
>>
>> Thanks,
>> Vince
>>
>> PS I've tried this on the notebook running on my machine and sagenb as
>> well...
>>
>> --
>> Dr Vincent Knight
>> Cardiff School of Mathematics
>> Senghennydd Road,
>> Cardiff
>> CF24 4AG
>> (+44) 29 2087 5548
>> www.vincent-knight.com
>> @drvinceknight <http://twitter.com/#!/drvinceknight>
>> Skype: drvinceknight
>>
>> --
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org
>
--
Dr Vincent Knight
Cardiff School of Mathematics
Senghennydd Road,
Cardiff
CF24 4AG
(+44) 29 2087 5548
www.vincent-knight.com
@drvinceknight <http://twitter.com/#!/drvinceknight>
Skype: drvinceknight
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org