import os or import os.path

Ian Kelly ian.g.kelly at
Tue Sep 6 17:47:57 EDT 2011

On Tue, Sep 6, 2011 at 3:25 PM, Jabba Laci <jabba.laci at> wrote:
> Hi,
> 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.


More information about the Python-list mailing list