Reading text file with wierd file extension?

Stephen Hansen apt.shansen at gmail.com
Mon Feb 2 13:55:26 EST 2009


>
> The above works well. I am able to open the file and read it's
> contents. I assume to read a file in text file "mode" the parameter is
> scanned for a ".txt" extension, otherwise the Python runtime doesn't
> know what version of "open(...)" to invoke. How do I pass the original
> filename (MyTextFile.slc.rsc) and get Python to open it as a text
> file? Thanks in advance everyone!


Python doesn't care what extension you use: it doesn't even look at it. The
full file name is passed blindly to the base OS.

To open a file in text mode, do open(filename, "r"); it opens in binary if
you do open(filename, "rb"). The filename has no impact on if its text or
binary mode.

There's something else going on here, I think, and you got misdirected from
it. Are you sure you didn't typo the Filepath slightly? Perhaps left off a \
or had a comma instead of a period -- etc? Or that the filename didn't have
some odd character in it that looked like a regular ascii character?

--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090202/6ac1ca9c/attachment.html>


More information about the Python-list mailing list