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)
The old answer assumes that you are writing information from an "iterable": a Python list or tuple or similar object. So replace "iterable" with the name of the list storing the information. If you want to write a single object X, not the entries of a list, just skip the
for
loop andprint(X, file=fp)
. This is not specific to Sage: any information on the internet about writing to a file with Python will be relevant.