Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.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.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:file': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:module': 0.09; 'python': 0.11; 'suggest': 0.14; 'economics,': 0.16; 'finney': 0.16; 'invoking': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'top-level': 0.16; '(the': 0.22; 'command': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; '(or': 0.24; 'header:X-Complaints- To:1': 0.27; 'chris': 0.29; 'writes:': 0.31; 'file': 0.32; 'run': 0.32; 'subject:from': 0.34; '8bit%:17': 0.36; 'so,': 0.37; 'being': 0.38; 'ben': 0.38; 'work?': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'hope': 0.61; 'great': 0.65; 'skip:\xe2 10': 0.65; '8bit%:40': 0.68; '8bit%:46': 0.78; 'coexist': 0.84; 'received:125': 0.84; 'way)': 0.84; 'faith': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: Import a module from a specific file path Date: Sat, 22 Nov 2014 17:46:11 +1100 References: <066c46c8-a04d-4489-b15a-b603c1b1818b@googlegroups.com> <8661e407-4472-4208-97c2-f666f6502c67@googlegroups.com> <0bbe1c60-2b29-40f6-96e1-ac777f0c276f@googlegroups.com> <08867178-abb6-4703-9ac5-2a53acb5d227@googlegroups.com> <85k32oysrg.fsf_-_@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:X0RcxyaC/fXbswdhTcsNDUydzeY= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 1416638782 news.xs4all.nl 2912 [2001:888:2000:d::a6]:60442 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81278 Chris Angelico writes: > So can you simply: > > $ python -m foo.fooprog > > ? (or 'python3', either way) So, that's a pretty awful user interface. (The file is named ‘fooprog’ because it's an executable, intended to be run directly at the command line.) That solution would be rather inferior to the program being able to import modules when invoked as the top-level program. Can you suggest solutions that allow invoking the program as ‘./fooprog’ to work? -- \ “In economics, hope and faith coexist with great scientific | `\ pretension and also a deep desire for respectability.” —John | _o__) Kenneth Galbraith, 1970-06-07 | Ben Finney