Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'subject:file': 0.07; '"__main__":': 0.09; '__name__': 0.09; 'main()': 0.09; 'parsing': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '*only*': 0.16; 'command-line': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'main():': 0.16; 'script,': 0.16; 'sense,': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'module': 0.19; 'cc:addr:python.org': 0.22; 'looks': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'skip:_ 20': 0.27; 'header :In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'specifically': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'usually': 0.31; '13,': 0.31; 'invoke': 0.31; 'skip:d 20': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'entry': 0.36; 'sometimes': 0.38; 'called': 0.40; 'ian': 0.60; 'tell': 0.60; 'real': 0.63; 'more': 0.64; '2015': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=U5nwItyIB07EN3h0VYWiuIUeCbtbERN3msmJYWZv614=; b=sbPM5wPjOQiqpFQKHlRbtepb+/oBhYk2EfjMOUTG+BTEtGqmOCt09jeRMXEPMtvWSi yuN6cxrE4p8cdNMm9z7h5bpiUfc7JYg5mnkVqKXGigNXsBLqYa9zgY4sjPIYnEm/Cp4H 3Z5WiSQpdHrwt9nTDD0q24G5AyoBNeCv8C2oNYSuUni3lnEyYU9nNr+5UEsWWlw74ceU k0mz0N5zcWDRsppJNLgoHdLa8tV0fySVV5n/Y+/Ge/w3d+B4gY8OQRNJmEe1HXDqyIWH EUx7c+xzg6cvAdkE+Kz9hqCTT3TOZ35iiYJ/SNFctEYHHyBTjFXI7rM1qaajrx1IE0PY ZGUw== MIME-Version: 1.0 X-Received: by 10.50.66.172 with SMTP id g12mr6069955igt.34.1431461251501; Tue, 12 May 2015 13:07:31 -0700 (PDT) In-Reply-To: References: Date: Wed, 13 May 2015 06:07:31 +1000 Subject: Re: Python file structure From: Chris Angelico Cc: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431461254 news.xs4all.nl 2922 [2001:888:2000:d::a6]:37364 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90487 On Wed, May 13, 2015 at 5:54 AM, Ian Kelly wrote: > Also, I like to put command-line parsing inside the main function and > make that its *only* responsibility. The main function then calls the > real entry point of my script, which will be something more > specifically named. This also has the advantage that if some other > module needs to invoke my script, all it has to do is call the entry > point function which will be named something more suitable than > "main". That often makes sense, but sometimes doesn't. When it doesn't, you can usually tell because your main function looks something like this: def main(): do_real_work(*sys.argv) if __name__=="__main__": main() A one-line function that's called from one place? In-line it. if __name__ == "__main__": do_real_work(*sys.argv) ChrisA