Problem with os module

Richard Chamberlain richard_chamberlainNOriSPAM at ntlworld.com.invalid
Wed Jun 28 10:02:26 EDT 2000


Hi Aline,

What you're doing (from os import *) is importing the contents
of os into your current namespace.

So path is available without the os. at the beginning.

It's not a good idea to do this though because if os uses any
method or variable names that you are using they'll get wiped
over.

So with that in mind you could either do:

from os import *
if path.isfile("c:\\Test"):

(not a good idea)

or:

import os

if os.path.isfile("c:\\Test"):

(much better)

b.t.w. you'll notice above that I've used c:\\Test - the reason
is that \ has a special meaning within a string. For instance \t
is a tab and \n a newline, \\ is in fact a single \. So your
paths should look something like "c:\\my folder\\my file".

>> I'm new on the list, and I'm french

I think we'll cope.

Richard



Got questions?  Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com




More information about the Python-list mailing list