Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.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; 'defaults': 0.05; 'initialize': 0.05; '(using': 0.07; '__name__': 0.07; 'indicated': 0.07; '__all__': 0.09; '__file__,': 0.09; 'instance.': 0.09; '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; 'callables': 0.16; 'differs': 0.16; 'lazily': 0.16; 'occur.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'skip:~ 20': 0.16; 'subject:instance': 0.16; 'settings': 0.20; 'work,': 0.21; 'trying': 0.22; 'default,': 0.22; 'bit': 0.23; 'module': 0.23; 'import': 0.24; 'seems': 0.24; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; "i'm": 0.29; 'objects': 0.29; 'file': 0.34; 'to:addr:python-list': 0.35; 'clear': 0.35; 'instance': 0.35; 'but': 0.36; 'there': 0.36; 'possible': 0.36; 'sources': 0.37; 'received:org': 0.38; 'to:addr:python.org': 0.39; 'utilize': 0.61; 'here': 0.66; 'overcome': 0.72; 'received:109': 0.75; 'trial': 0.81; 'becker': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robin Becker Subject: instance as module Date: Fri, 19 Jun 2015 10:29:14 +0100 Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 109.174.168.73 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1434706168 news.xs4all.nl 2966 [2001:888:2000:d::a6]:59468 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92873 I'm trying to overcome a recursive import issue in reportlab. Module reportlab.rl_config uses various sources (eg ~/.reportlab_settings) to initialize various defaults eg canvas_basefontname. If a user wants to utilize reportlab to set up such a default, it's not possible to do so in the settings file because a recursive import would occur. Normal defaults are always primitive python objects eg float/int/str etc etc. If I make the rl_config module into an object (using the GvR blessed approach indicated here http://stackoverflow.com/questions/2447353/getattr-on-a-module) then I can use callables in the settings module and get them evaluated lazily which overcomes the recursion. Are there any gotcha's that need to be considered when using this instance as module approach? My trial implementation seems to work, but it's not clear exactly how a module differs from an instance. I have set various dunders on the instance eg __file__, __doc__, __all__ & __name__ and I made the object a borg, but it still seems a bit hacky. -- Robin Becker