On Fri, Nov 20, 2009 at 10:40 AM, Dave Angel <span dir="ltr">&lt;<a href="mailto:davea@ieee.org">davea@ieee.org</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5">Eric Pavey wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Fri, Nov 20, 2009 at 4:09 AM, Kent Johnson &lt;<a href="mailto:kent37@tds.net" target="_blank">kent37@tds.net</a>&gt; wrote:<br>
<br>
  <br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Thu, Nov 19, 2009 at 9:31 PM, Eric Pavey &lt;<a href="mailto:warpcat@gmail.com" target="_blank">warpcat@gmail.com</a>&gt; wrote:<br>
    <br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Say I have this package layout<br>
<br>
\myPackage<br>
<br>
__init__.py<br>
moduleA.py<br>
moduleB.py<br>
<br>
Is there a way (and I&#39;m sure there is...) to query, for a given package<br>
level, which modules live under it?<br>
I thought I could do it like so:<br>
<br>
import myPackage<br>
goodQualityInfo = dir(myPackage)<br>
      <br>
</blockquote>
One way to do this is to include an __all__ attribute in __init__.p]:<br>
__all__ = [&#39;moduleA&#39;, &#39;moduleB&#39;]<br>
<br>
Then instead of dir(myPackage) use myPackage.__all__.<br>
<br>
The name is standard though it is usually used for a slightly different<br>
purpose:<br>
<a href="http://docs.python.org/tutorial/modules.html#importing-from-a-package" target="_blank">http://docs.python.org/tutorial/modules.html#importing-from-a-package</a><br>
<br>
Kent<br>
</blockquote>
<br>
Thanks.  I was considering that too, but I want to be able to have people<br>
drop modules in that dir and &quot;be done with it&quot;:  Not also have them also<br>
need to update __all__ in __init__.py<br>
Appreciate the suggestion though.<br>
My current hacky plan is just query the location on disk of the imported<br>
package, then do a dir search for .py files in that dir, and process those.<br>
Seems clunky though.<br>
<br>
</blockquote></div></div>
Doesn&#39;t seem clunky to me.  And if you do it in __init__.py, you can use the __file__ attribute to get your base directory.  Just put the results in __all__ and you combine both ideas.<br>
<br>
DaveA<br></blockquote><div> </div></div>Starting to like that more ;)<br>
thanks