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


Groups > comp.lang.python > #11301

Re: __all__

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
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; 'python?': 0.05; 'situation.': 0.05; 'practice,': 0.07; '(defined': 0.09; 'exceptions,': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'func': 0.09; 'lately': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; '~ethan~': 0.09; 'classes,': 0.13; 'def': 0.15; '(towards': 0.16; '*args):': 0.16; 'blah': 0.16; 'importable': 0.16; 'normally.': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'cc:addr:python-list': 0.16; 'written': 0.16; 'wrote:': 0.16; 'thanks,': 0.18; 'programming': 0.20; 'cc:no real name:2**0': 0.20; 'stuff': 0.22; 'header:In- Reply-To:1': 0.22; 'etc,': 0.23; 'module,': 0.23; 'paul': 0.28; 'somebody': 0.28; 'separate': 0.28; 'correct': 0.28; 'import': 0.28; 'specifically': 0.29; 'cc:addr:python.org': 0.30; 'module': 0.30; 'thanks': 0.30; 'class': 0.30; 'list': 0.32; 'that,': 0.33; 'header:User-Agent:1': 0.34; 'primary': 0.36; 'cc:2**1': 0.36; 'but': 0.37; 'something': 0.37; 'some': 0.38; 'accepted': 0.38; 'subject:: ': 0.39; 'else': 0.39; 'define': 0.39; 'needed.': 0.39; 'called': 0.40; 'thinking': 0.40; 'charset:windows-1252': 0.60; 'your': 0.61; 'back': 0.62; 'projects': 0.63; 'bottom': 0.64; 'received:websitewelcome.com': 0.64; 'received:184': 0.67; 'received:69.93': 0.67
Date Fri, 12 Aug 2011 13:15:52 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To Paul Woolcock <pwoolcoc@gmail.com>
Subject Re: __all__
References <mailman.2070.1312906708.1164.python-list@python.org> <4e416705$0$29988$c3e8da3$5496439d@news.astraweb.com> <CACNEfZa6bKmh6Ysdap1hcute92__ga5X94dWx9oO4Vdh6jQL4Q@mail.gmail.com>
In-Reply-To <CACNEfZa6bKmh6Ysdap1hcute92__ga5X94dWx9oO4Vdh6jQL4Q@mail.gmail.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:1075
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 2
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
Cc python-list@python.org, Steven D'Aprano <steve+comp.lang.python@pearwood.info>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2231.1313179180.1164.python-list@python.org> (permalink)
Lines 48
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1313179180 news.xs4all.nl 23852 [2001:888:2000:d::a6]:42410
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:11301

Show key headers only | View raw


Paul Woolcock wrote:
> The gurus will have to correct me if this is not an accepted practice, 
> but I know some projects (Fabric is the one that comes to mind) will 
> define a submodule specifically for the 'from blah import *' situation. 
> The submodule would be called "api", or something like that, so you can 
> do: 'from mymodule.api import *' to separate the items you want to 
> include in your public api, while still keeping other names importable 
> by 'import blah'

Have I said lately how much I *love* Python?  Programming is fun again!

Thanks, Paul, that was the clue I needed.  Had to do some thinking since 
dbf is back to a single module, and no longer a package... here's what I 
came up with:

-------------------------------------------------------------
class fake_module(object):
     def __init__(self, name, *args):
         self.name = name
         self.__all__ = []
         for func in args:
             name = func.__name__
             self.__dict__[name] = func
             self.__all__.append(name)
     def register(self):
         sys.modules["%s.%s" % (__name__, self.name)] = self
-------------------------------------------------------------

then in my module (towards the bottom since I have to have all my 
functions/classes written that I want to include) I can have

fake_module('api', class1, class2, func1, exception1).register()

Now somebody else who wants to include the classes, exceptions, etc, 
that make up the primary part of the dbf module can do

from dbf.api import *

but

help(dbf)

will continue to list all the other public utility stuff (defined in 
dbf.__all__) normally.

Thanks to all!

~Ethan~

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


Thread

__all__ Ethan Furman <ethan@stoneleaf.us> - 2011-08-09 09:34 -0700
  Re: __all__ Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-10 02:57 +1000
    Re: __all__ Ethan Furman <ethan@stoneleaf.us> - 2011-08-12 13:15 -0700

csiph-web