Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2a.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'parameters': 0.04; 'yet.': 0.04; 'subject:Python': 0.06; 'definitions': 0.07; 'subject:file': 0.07; '"__main__":': 0.09; '__name__': 0.09; 'main()': 0.09; 'parsing': 0.09; 'uses.': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'assignments': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; "function's": 0.16; 'main():': 0.16; 'occurs,': 0.16; 'tends': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'variable': 0.18; 'wed,': 0.18; 'possible,': 0.19; 'command': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'error': 0.23; 'file.': 0.24; 'cc:2**0': 0.24; 'source': 0.25; 'options': 0.25; 'script': 0.25; 'defined': 0.27; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'generally': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; '13,': 0.31; 'probably': 0.32; "i'd": 0.34; 'definition': 0.35; 'requirement': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'itself': 0.39; 'how': 0.40; 'helps': 0.61; 'strictly': 0.61; 'simple': 0.61; 'first': 0.61; 'here:': 0.62; 'high': 0.63; 'such': 0.63; '2015': 0.84; 'calls,': 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=PWrtfjpSLHSp+lVrJuInRQcLfrgwzuzZyU7PO8Xly7U=; b=RGOk99PWmttcqYj64ekxxfyppU7sYE6yA2xHtZl92GTqEorj23bF3GdZC0HG6szkf2 JbmezxBYAq1dEQ7cXNwN1TEM3EUNTQT1iHm5dmEynSKLPbi0VWT3OTyk1M//MfK27nbv 9Bk+bjgTjkOWqtUoodwL3jODLc1rtylSe9NP++m5XK8L1OMQEstAXFbY4YK+PDM12pLf FhCiGqGQ20HQFTvZJYFgMnPf/6FOtMDH6XwbBXfiMU1ekkHSdO0GF5RkAhAm8viVF7Nu 3iK2/NW0va8Kz+yP2E2VlD6gU9hqxQF0eOCBgQDbol2YJODVd2GpL3LpP3gnWdirurPx Vj2A== MIME-Version: 1.0 X-Received: by 10.43.39.1 with SMTP id tk1mr3275794icb.26.1431458988941; Tue, 12 May 2015 12:29:48 -0700 (PDT) In-Reply-To: References: Date: Wed, 13 May 2015 05:29:48 +1000 Subject: Re: Python file structure From: Chris Angelico Cc: "python-list@python.org" 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431458997 news.xs4all.nl 2827 [2001:888:2000:d::a6]:45851 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90481 On Wed, May 13, 2015 at 5:13 AM, wrote: > import... > > A = configparser.get(...) > B = configparser.get(...) > > Command line parameters parsing [they can change variable A or B] > > Def usage() > Print how to use script parameters > > def main(): > ... > > if __name__ == "__main__": > main() > > If I find an error in command line parameters section I cannot call function usage() because it is not defined yet. > > I have few options here: > 1. Put definition of usage function before command line parameters parsing section I'd do this, unless there's a good reason not to. A simple usage function probably doesn't have many dependencies, so it can logically go high in the code. As a general rule, I like to organize code such that things are defined higher up than they're used; it's not strictly necessary (if they're used inside functions, the requirement is only that they be defined before the function's called), but it helps with clarity. That generally means that "def usage():" wants to go up above any place where "usage()" occurs, but below the definitions of any functions that usage() itself calls, and below the first assignments to any global names it uses. It's not always possible, but when it is, it tends to produce an easy-to-navigate source file. ChrisA