Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to output from sage (update)

This question was answered there 12 years ago. I was using the code from ccanonc

with open("outputfilepath", 'w') as > fp:
>     for line in iterable: #assuming line is str with \n
>         print >> fp, line
> #implicit fp.close() here as "with" scope endsto

today with python 3 and sage 9.5, I get: NameError: name 'iterable' is not defined

What is the easiest way to update this code?

How to output from sage (update)

This question was answered there 12 years ago. I was using the code from ccanonc

with open("outputfilepath", 'w') as > fp:
>     for line in iterable: #assuming line is str with \n
>         print >> fp, line
> #implicit fp.close() here as "with" scope endsto

today with python 3 and sage 9.5, I get: NameError: name 'iterable' is not defined

What is the easiest way to update this code?

Note that the line

print >> fp, line

is converted in

print(line, file=fp)