Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.albasani.net!newsfeed.freenet.ag!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.019 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'dynamically': 0.07; 'classes.': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; '*this*': 0.16; 'dict': 0.16; 'globals.': 0.16; 'scope.': 0.16; 'subject:class': 0.16; 'to:addr:web.de': 0.16; 'wrote:': 0.18; '(not': 0.18; 'module': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'idea': 0.28; 'point': 0.28; 'message- id:@mail.gmail.com': 0.30; 'that.': 0.31; '>>>>': 0.31; 'skip:m 30': 0.32; 'cases': 0.33; "i'd": 0.34; 'agree': 0.35; 'created': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'within': 0.65; 'skip:m 50': 0.68; 'otten': 0.84; 'do:': 0.91; 'good,': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=cKd3OUoIhDSPHhVEQ7XUTm7WogpMMECilf94kt7hx+M=; b=rv/xRQzr1TKGm6z1V6EQyTNZzm8LHD1MkOK3D0B2Hzl0oOrsS9RgNOmDk2+surgmCW 0VwuQ/kbtEZO4zQYGxhBMw0QoWFGxmGINpCD6OGIzFjTjyLGjpEiPn7RhivpSfwDgSwF MTfFzh+J4xiBI3X/pvIGt7lemPljXP9yyQERomv7km/hDueefjZEAHkrB//8jhd4Fb5a 6Vmdqdk0YBICxyvAboD0zJmfIxQKAjY+Cn44nbXP3SFmqGvcb0+JyW2Hiasj0MmR3f+/ OOygH7k5RodT7GbtU79Z+U7PlLxnNLqWB4IuAPyqfba2JdYfErDCCJ54Xbm4j0xcoAcT XBRA== X-Received: by 10.152.42.171 with SMTP id p11mr2841378lal.79.1372288860284; Wed, 26 Jun 2013 16:21:00 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <138ce5a8-1b4c-49d4-8005-d5f4642dcb97@googlegroups.com> <5d6aa501-58f6-4d8f-8bf5-53d95ff9264e@googlegroups.com> From: Joshua Landau Date: Thu, 27 Jun 2013 00:20:20 +0100 Subject: Re: class factory question To: Peter Otten <__peter__@web.de> Content-Type: text/plain; charset=UTF-8 Cc: python-list 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372288868 news.xs4all.nl 15864 [2001:888:2000:d::a6]:56003 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49285 On 26 June 2013 16:40, Peter Otten <__peter__@web.de> wrote: > Joshua Landau wrote: > >> I would say if a dict isn't good, there are still some cases where you >> might not want to use globals. >> >> I _might_ do: > >> # Make a module >> module_for_little_classes = ModuleType("module_for_little_classes", >> "All the things") >> module_for_little_classes.__dict__.update(little_classes) > > Hm, from within module_for_little_classes that is globals(). To illustrate: > >>>> import __main__ as main >>>> globals() is main.__dict__ > True Yes, that's true - but the point wasn't not to use "globals the function", but not to use *this* global scope. > Also, I'd spell module.__dict__ vars(module). Again, good catch. Definitely that. > That said I agree that it's a good idea to use a dedicated module (not > necessarily created on the fly) for those dynamically generated classes.