Fw: Newbie - help in opening and reading a file from >>>

David Fisher python at rose164.wuh.wustl.edu
Sun Mar 26 22:03:17 EST 2000


> ----- Original Message -----
> From: "Dan Howard" <va3ma at rac.ca>
> Newsgroups: comp.lang.python
> To: <python-list at python.org>
> Sent: Sunday, March 26, 2000 12:09 PM
> Subject: Newbie - help in opening and reading a file from >>>
>
>
> > Hi
> > I've just installed 1.5 on my Windows 98Se system
> > I'm trying to execute the following-
> > >>>f=open('C:\Autoexec.bat')
> > and I get a no such directory or file error
> > Is there some parameter or path that I must set?
> >  Would apprecaite any clues
>
> Hi,
> You need to use a raw string.  Raw string won't process '\' as an escape.
> Like this: r'this is a raw string'
> example:
>
> >>> f = open(r'c:\config.sys')
> >>> f.read()
> 'DEVICEHIGH=C:\\WINDOWS\\COMMAND\\DRVSPACE.SYS
> /MOVE\012SHELL=C:\\COMMAND.COM /E:4096 /p /L:1024 /U:255\012'
>
> Or you need to use the escape to make a \. Like this: '\\this string
starts
> with a slash'
> example:
>
> >>> f = open('c:\\config.sys')
> >>> f.read()
> 'DEVICEHIGH=C:\\WINDOWS\\COMMAND\\DRVSPACE.SYS
> /MOVE\012SHELL=C:\\COMMAND.COM /E:4096 /p /L:1024 /U:255\012'
>
> Some other useful escapes are:
> '\n'    newline
> '\t'    tab
> '\0'    null char
>
> Good luck,
> David
>
>





More information about the Python-list mailing list