import os or import os.path
skippy.hammond at gmail.com
Wed Sep 7 03:11:55 CEST 2011
On 7/09/2011 7:47 AM, Ian Kelly wrote:
> On Tue, Sep 6, 2011 at 3:25 PM, Jabba Laci<jabba.laci at gmail.com> wrote:
>> If I want to use the 'os.path' module, it's enought to import 'os':
>> import os
>> if os.path.isfile('/usr/bin/bash'):
>> print 'got it'
>> In other source codes I noticed that people write 'import os.path' in
>> this case. Which is better practice?
> "import os.path" is better practice. There is no guarantee in general
> that the os module will automatically import os.path, and in future
> versions or different implementations it might not.
That's probably a matter of opinion - eg,
http://docs.python.org/tutorial/interpreter.html has an example of
importing the os module then accessing os.path.
Personally I think directly importing os.path is a waste of precious
More information about the Python-list