On Monday, 26 March 2012 05:12:12 UTC+8, William Stein wrote:
>
> On Sun, Mar 25, 2012 at 9:06 AM, Dima Pasechnik <dimp...@gmail.com> wrote:
> > OK, thanks for letting su know. It looks like a genuine bug, indeed.
> > The issue is now reported to sagenb folks as
> > https://github.com/sagemath/​sagenb/issues/48<https://github.com/sagemath/sagenb/issues/48>
>
> I think you should close that.  The following works fine in the
> notebook.   It makes no sense to close the file -- instead, you have
> to delete the csv writer object, which flushes it to the file.
>
> import csv
> output=csv.writer(open('test.​csv','wb'))
> data=[[1,2],[3,4],[5,6]]
> for r in data:
>     output.writerow(r)
>
> del output
>

wow, *deleting* does this?!  
I duly sought close() method for output, didn't find it...

Another question is why this is not needed at sage prompt. Different 
behaviour in shell and in nb is never good, IMHO.

> >
> >
> > On Sunday, 25 March 2012 20:05:43 UTC+8, Vincent Knight wrote:
> >>
> >> 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 <dimp...@gmail.com> 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
> >>>> Skype: drvinceknight
> >>>>
> >>> --
> >>> To post to this group, send email to sage-support@googlegroups.com
> >>> To unsubscribe from this group, send email to
> >>> sage-support+unsubscribe@​googlegroups.com<sage-support%2bunsubscr...@googlegroups.com>
> >>> For more options, visit this group at
> >>> http://groups.google.com/​group/sage-support<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
> >> Skype: drvinceknight
> >>
> >
>
> -- 
> William Stein
> Professor of Mathematics
> University of Washington
> http://wstein.org
>
>

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to