Reading text file with wierd file extension?

Lionel lionel.keene at gmail.com
Mon Feb 2 20:21:54 CET 2009


On Feb 2, 11:20 am, Lionel <lionel.ke... at gmail.com> wrote:
> On Feb 2, 10:41 am, Mike Driscoll <kyoso... at gmail.com> wrote:
>
>
>
>
>
> > On Feb 2, 12:36 pm, Lionel <lionel.ke... at gmail.com> wrote:
>
> > > Hi Folks, Python newbie here.
>
> > > I'm trying to open (for reading) a text file with the following
> > > filenaming convension:
>
> > > "MyTextFile.slc.rsc"
>
> > > My code is as follows:
>
> > > Filepath = "C:\\MyTextFile.slc.rsc"
> > > FileH = open(Filepath)
>
> > > The above throws an IOError exception. On a hunch I changed the
> > > filename (only the filename) and tried again:
>
> > > Filepath = "C:\\MyTextFile.txt"
> > > FileH = open(Filepath)
>
> > > 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!
>
> > The extension shouldn't matter. I tried creating a file with the same
> > extension as yours and Python 2.5.2 opened it and read it no problem.
> > I tried it in IDLE and with Wing on Windows XP. What are you using?
> > What's the complete traceback?
>
> > Mike- Hide quoted text -
>
> > - Show quoted text -
>
> Hi Mike,
>
> maybe it's not a "true" text file? Opening it in Microsoft Notepad
> gives an unformatted view of the file (text with no line wrapping,
> just the end-of-line square box character followed by more text, end-
> of-line character, etc). Wordpad opens it properly i.e. respects the
> end-of-line wrapping. I'm unsure of how these files are being
> generated, I was just given them and told they wanted to be able to
> read them.
>
> How do I collect the traceback to post it?- Hide quoted text -
>
> - Show quoted text -

Sorry, I forgot to mention I'm using Python 2.5 and the Python IDLE.



More information about the Python-list mailing list