"import" not working?

Aahz aahz at pythoncraft.com
Thu Mar 12 11:42:52 EDT 2009


In article <mailman.605.1235434737.11746.python-list at python.org>,
Rhodri James <rhodri at wildebst.demon.co.uk> wrote:
>
>Just so that we're clear, this is a *really* *bad* habit to get into.
>Not appending to sys.path, though that isn't often a good idea, but
>failing to escape your backslashes.  This works because '\D' happens
>not to be a valid escape sequence: if your directory had instead been
>called "newtypes" then "C:\newtypes" would not have had the result you
>were expecting at all.  If you really mean a backslash to be in any
>literal string, you should always double it:
>
>sys.path.append("C:\\DataFileTypes")

My preference:

sys.path.append(r"C:\DataFileTypes")

This doesn't work if you need to add a trailing backslash, though.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of     
indirection."  --Butler Lampson



More information about the Python-list mailing list