Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12865 > unrolled thread

Re: import os or import os.path

Started byMark Hammond <skippy.hammond@gmail.com>
First post2011-09-07 11:11 +1000
Last post2011-09-07 11:11 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: import os or import os.path Mark Hammond <skippy.hammond@gmail.com> - 2011-09-07 11:11 +1000

#12865 — Re: import os or import os.path

FromMark Hammond <skippy.hammond@gmail.com>
Date2011-09-07 11:11 +1000
SubjectRe: import os or import os.path
Message-ID<mailman.815.1315358357.27778.python-list@python.org>
On 7/09/2011 7:47 AM, Ian Kelly wrote:
> On Tue, Sep 6, 2011 at 3:25 PM, Jabba Laci<jabba.laci@gmail.com>  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.

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 
keystrokes ;)

Cheers,

Mark.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web