On Sat, Aug 23, 2008 at 9:56 AM, Wayne Watson
<[EMAIL PROTECTED]> wrote:
> Python doesn't like this:
>
> junkfile = open('c:\tmp\junkpythonfile','w')
>
> I get
>     junkfile = open('c:\tmp\junkpythonfile','w')
> IOError: [Errno 2] No such file or directory: 'c:\tmp\\junkpythonfile'

The \ character is a special 'escape' character that is used to insert
non-printing characters into a string. \t represents a single tab
character, not the two characters \ and t.

To put an actual backslash into a string, you can either double it:
  'c:\\tmp\\junkpythonfile'
or prefix the string with r to make a 'raw' string, which doesn't have
any special meaning for \:
  r'c:\tmp\junkpythonfile'

Kent
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to