Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92876

Re: instance as module

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 <python-python-list@m.gmane.org>
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:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'skip:~ 20': 0.16; 'subject:instance': 0.16; 'wrote:': 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; 'being': 0.36; 'there': 0.36; 'possible': 0.36; 'subject:: ': 0.37; 'sources': 0.37; 'received:org': 0.38; 'to:addr:python.org': 0.39; 'received:de': 0.40; 'even': 0.61; 'utilize': 0.61; 'more': 0.62; 'making': 0.64; 'here': 0.66; 'situation': 0.67; 'overcome': 0.72; 'hoping': 0.73; 'trial': 0.81; 'becker': 0.84; 'bitten': 0.84; 'correctly?': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: instance as module
Date Fri, 19 Jun 2015 12:23:09 +0200
Organization None
References <5583E0EA.2090309@chamonix.reportlab.co.uk>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p57bd8d4f.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.629.1434709413.13271.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1434709413 news.xs4all.nl 2862 [2001:888:2000:d::a6]:52370
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:92876

Show key headers only | View raw


Robin Becker wrote:

> 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.

Do I understand this correctly? You got bitten by a complex setup and now 
you are hoping to improve the situation by making it even more complex?

How about reordering initialisation in such a way that the user defaults are 
the last thing being set?

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: instance as module Peter Otten <__peter__@web.de> - 2015-06-19 12:23 +0200

csiph-web