Newbie - help in opening and reading a file from >>>
Dennis E. Hamilton
infonuovo at email.com
Sun Mar 26 15:14:49 EST 2000
Dan,
I just did
>>> f = open('c:\\autoexec.bat')
with Python 1.5.2 on Windows 98 SE and it worked just fine. I surmise you
were caught by the
\-as-escape-character feature of Python strings. (It's the same feature in
C and C++ and Java, so it is a lesson you only have to learn once.)
This is probably in the FAQ somewhere (I'm one of those people who hasn't
RTFAQ yet).
Here's the basic principle: To put a single \-character into a simple text
string, you write two consecutive \-characters.
Here's more than you might want to know right now: When a \-character
occurs in a string literal, it is treated as an "escape" that has the
immediately-following character(s) be interpreted differently. This device
allows you to create the character codes for some special characters
(including and ' and ") in strings. The way to get a literal \-character is
to escape one: write one \-character followed by another. Tidy, huh?
There's nothing obvious about this. It is one of those things you just have
to learn.
There is a python-tutor list that is a good place to discuss more of these
kinds of things. Visit http://www.python.org/mailman/listinfo/tutor for
more information.
-- Dennis
------------------
Dennis E. Hamilton
InfoNuovo
mailto:infonuovo at email.com
tel. +1-206-779-9430 (gsm)
fax. +1-425-793-0283
http://www.infonuovo.com
-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Dan Howard
Sent: Sunday, March 26, 2000 10:10
To: python-list at python.org
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...
Dan
--
http://www.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list