I'll have to try this again. I obviously did something wrong in my code. I was
getting errors about not being able to write a string because it wasn't
supported. It was driving me nuts for a while until I just gave up and went
back to open(). I'll do some more playing and if I continue to get
Peter A. Schott wrote:
Thanks to all who replied. If open is still preferred, I will
stick with that.
FWIW, that's not an unqualified preferred. To demonstrate by example,
neither of the above is considered preferred, though they both work:
outputFile = file('path.to.file')
if
Peter A. Schott wrote:
I'll have to try this again. I obviously did something wrong in my code. I
was
getting errors about not being able to write a string because it wasn't
supported. It was driving me nuts for a while until I just gave up and went
back to open().
I expect somewhere
Been reading the docs saying that file should replace open in our code, but this
doesn't seem to work:
# Open file for writing, write something, close file
MyFile = file(MyFile.txt, w)
MyFile.write(This is a test.)
MyFile.close()
However, using:
MyFile = open(MyFile.txt, w)
MyFile.write(This is
Peter A. Schott wrote:
Been reading the docs saying that file should replace open in our code, but
this
doesn't seem to work:
This was really a misstatement; open is still preferred. file is now
a built in class, and its constructor is the same as open. I think the
current docs have been
In article [EMAIL PROTECTED],
Peter A. Schott [EMAIL PROTECTED] wrote:
Been reading the docs saying that file should replace open in our code, but
this
doesn't seem to work:
# Open file for writing, write something, close file
MyFile = file(MyFile.txt, w)
MyFile.write(This is a test.)
Both your code snippets above work should work OK. If it seems like a
file isn't being written, maybe you should specify its full path so you
are sure about where to check for it.
On the file-or-open question, the Python docs state, The intent is for
open() to continue to be preferred for use as
Peter A.Schott wrote:
Been reading the docs saying that file should replace open in our code, but
this
doesn't seem to work:
# Open file for writing, write something, close file
MyFile = file(MyFile.txt, w)
MyFile.write(This is a test.)
MyFile.close()
However, using:
MyFile =
Peter A.Schott wrote:
Been reading the docs saying that file should replace open in our code,
but this
doesn't seem to work:
what docs?
open is the preferred way to open a file. file is a type constructor.
in contemporary python, they happen to map to the same callable, but
that's not