Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'keystrokes': 0.09; 'am,': 0.12; 'case.': 0.15; '"import': 0.16; 'from:name:mark hammond': 0.16; "it'": 0.16; 'practice?': 0.16; 'received:192.168.0.9': 0.16; 'reply-to:addr:mhammond': 0.16; 'reply- to:addr:skippinet.com.au': 0.16; 'subject:import': 0.16; 'cc:addr :python-list': 0.16; 'wrote:': 0.16; 'cheers,': 0.18; 'header:In- Reply-To:1': 0.22; 'tue,': 0.23; 'versions': 0.23; 'module,': 0.23; 'sep': 0.23; 'noticed': 0.24; 'pm,': 0.24; 'import': 0.28; 'importing': 0.29; 'print': 0.29; 'cc:addr:python.org': 0.30; 'example': 0.30; 'cc:addr:gmail.com': 0.30; 'module': 0.30; 'not.': 0.30; 'kelly': 0.30; 'hi,': 0.32; 'source': 0.33; 'probably': 0.33; 'there': 0.33; 'header:User-Agent:1': 0.34; 'message-id:@gmail.com': 0.34; 'received:209.85.161': 0.35; 'url:python': 0.36; 'cc:2**1': 0.36; 'think': 0.38; 'received:google.com': 0.38; 'url:org': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'url:docs': 0.39; 'might': 0.40; "it's": 0.40; 'skip:o 30': 0.63; 'guarantee': 0.66; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'precious': 0.77; 'mark.': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=FJxGmcYWSzzgSi36Ze6Pj9yjNJvOBaW6noPcVSgVKfc=; b=pyCeZeOl/txIYp5EulgbZg0a1DDZMNyMJMhU8YU8MWDpa/XqPw48U/YVidYTP1UuNu EBitO2DqF8skl+Wh0v5My1FsMdz0fOR+EaHcqsU1e6c/Xy4eEwQcSonak78SAsjbMKHt E/92JW75T8An6dId2msfVHoa6BBVlaj0TosAI= Date: Wed, 07 Sep 2011 11:11:55 +1000 From: Mark Hammond User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1 MIME-Version: 1.0 To: Ian Kelly Subject: Re: import os or import os.path References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Python mailing list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: mhammond@skippinet.com.au List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315358357 news.xs4all.nl 2519 [2001:888:2000:d::a6]:35513 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12865 On 7/09/2011 7:47 AM, Ian Kelly wrote: > On Tue, Sep 6, 2011 at 3:25 PM, Jabba Laci 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.