Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'package,': 0.03; 'startup': 0.04; 'imports': 0.07; 'modules.': 0.07; 'problem:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'am,': 0.12; '(none': 0.16; 'constants': 0.16; 'kitchen': 0.16; 'subject:import': 0.16; 'sure,': 0.16; 'this:': 0.16; 'wrote:': 0.16; 'solution.': 0.17; 'functions,': 0.18; 'loading': 0.18; 'memory': 0.21; 'math': 0.21; "doesn't": 0.22; 'header:In-Reply- To:1': 0.22; 'thus': 0.23; '(just': 0.23; 'module,': 0.23; 'somehow': 0.23; 'tool,': 0.23; 'command': 0.24; 'code': 0.25; "i'm": 0.27; '(the': 0.28; 'putting': 0.28; 'separate': 0.28; 'tools,': 0.28; 'import': 0.28; 'explicitly': 0.29; 'module.': 0.29; 'django': 0.29; 'module': 0.30; 'agreed.': 0.30; 'imported': 0.30; 'sub': 0.30; 'thanks': 0.30; 'too': 0.33; 'to:addr:python- list': 0.33; 'instead': 0.33; 'header:User-Agent:1': 0.34; 'idea': 0.34; 'defining': 0.34; 'frame': 0.34; 'subject: ?': 0.34; 'header:X-Complaints-To:1': 0.35; '(for': 0.35; 'certain': 0.35; 'question': 0.36; 'example,': 0.37; 'subject:skip:p 10': 0.37; 'using': 0.37; 'but': 0.37; 'something': 0.37; 'could': 0.38; 'received:org': 0.38; 'steven': 0.38; 'allows': 0.38; 'some': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'header:Mime-Version:1': 0.39; 'empty': 0.39; 'why': 0.39; 'to:addr:python.org': 0.39; 'might': 0.40; 'huge': 0.61; 'your': 0.61; 'tiny': 0.64; 'stated': 0.67; 'subject:without': 0.67; '06:51': 0.84; '95%': 0.84; 'choice:': 0.84; 'package?': 0.84; 'penalty': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Gelonida N Subject: Re: import packet.module without importing packet.__init__ ? Date: Sun, 11 Sep 2011 16:17:56 +0200 References: <4e6c074c$0$29990$c3e8da3$5496439d@news.astraweb.com> <4e6c3e47$0$29999$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: unicorn.dungeon.de User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.21) Gecko/20110831 Lightning/1.0b2 "" In-Reply-To: <4e6c3e47$0$29999$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315750692 news.xs4all.nl 2441 [2001:888:2000:d::a6]:50794 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:13127 Hi Steven, Thanks again for your answer. On 09/11/2011 06:51 AM, Steven D'Aprano wrote: > Gelonida N wrote: > > In your example, you stated that kitchen explicitly imports kitchen.pans and > kitchen.knives. So in that case, take it up with the designer of the > kitchen package -- it was his decision to import them, just like he > imported re and math and httplib. (For example.) Exactly. Thus my conclusion, that too many imports (just for commodity) in __init__.py might not be such a good idea if one wants to allow leaf-only imports. > > If kitchen is your package, then it is your choice: if you want to have > control over when sub-packages get imported, then don't automatically > import them in __init__.py. Agreed. This is however my problem: Up to my understanding rpc4django insists on putting code into __init__.py > > >> One package in question is a huge django application. >> >> Within the package is one module defining some constants and tiny >> functions, which I would like to reuse from some command line tools, >> which should start quickly without loading any of the django specific >> modules. (the startup penalty and the memory overhead would be noticable) >> >> I am using rpc4django, which expects, that __init__.py of the django >> application exports some all rpc functions >> which will basically import 95% of the django application and the entire >> django frame work (none of which were required by my command tool, >> support utility for this application) >> >> >> I could of course create a separate package just for this tiny sub >> module, but somehow it doesn't feel right to me. > > Why should it be a package? Just make it a stand-alone module. True > Or do something like this: > > my_app/ > +-- __init__.py # lightweight, nearly empty > +-- cmd_tools.py > +-- module1.py > +-- module2.py > +-- rpc/ > +-- __init__.py # huge, imports my_app.module1, my_app.module2, etc. > > then point rpc4django at my_app.rpc instead of my_app. > Up to my knowledge rpc4django just imports all __inits__ of all django applications to find look for functions with a certain decorator. I'm not sure, whether django allows nested appllications, but this might be a solution.