[Tutor] Opening files - Newbie Question

D-Man dsh8290@rit.edu
Tue, 17 Jul 2001 17:12:53 -0400


On Tue, Jul 17, 2001 at 01:37:48PM -0700, Sheila King wrote:

| You need to type the full path to the file "bruce". Is it in the same
| directory as your script? If not, you must type the full path.

It doesn't need to be an absolute path, a relative path is fine.  A
relative path must be relative to os.getcwd()

| When you are prompted to enter the file name, you need to enter
| something like:
| 
| C:\path\to\file\bruce.ext
         ^^      ^^

This path, while bogus, shows why windows paths are particularly evil.
Here is an example :

>>> path = "C:\path\to\file\bruce.ext"
>>> print path
C:\path o?ilruce.ext
>>>

The '\t' expands to a tab and '\b' expands to a backspace character.
It's not likely you have paths containing such characters.  The
backspace character might not even be legal on windows, I'm not sure.

Ok, so if you get the input using raw_input it will work, but not if
you write the paths in your code.  Use forward slashes instead -- the
open() function (and the underlying fopen() function) will be
perfectly happy with them.

-D