Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes you can use the imports from the other file by going a.os.</p> <p>However, the pythonic way is to just import the exact modules you need without making a chain out of it (which can lead to circular references).</p> <p>When you import a module, the code is compiled and inserted into a dictionary of names -> module objects. The dictionary is located at sys.modules.</p> <pre><code>import sys sys.modules &gt;&gt;&gt; pprint.pprint(sys.modules) {'UserDict': &lt;module 'UserDict' from 'C:\python26\lib\UserDict.pyc'&gt;, '__builtin__': &lt;module '__builtin__' (built-in)&gt;, '__main__': &lt;module '__main__' (built-in)&gt;, '_abcoll': &lt;module '_abcoll' from 'C:\python26\lib\_abcoll.pyc'&gt;, # the rest omitted for brevity </code></pre> <p>When you try to import the module again, Python will check the dictionary to see if its already there. If it is, it will return the already compiled module object to you. Otherwise, it will compile the code, and insert it in sys.modules.</p> <p>Since dictionaries are implemented as hash tables, this lookup is very quick and takes up negligible time compared to the risk of creating circular references.</p> <blockquote> <p>Edit: I'm not worried about the import times, my problem is the visual clutter that the block of imports puts on the files.</p> </blockquote> <p>If you only have about 4 or 5 imports like that, its not too cluttery. Remember, "Explicit is better than implicit". However if it really bothers you that much, do this:</p> <pre><code>&lt;importheaders.py&gt; from django.utils import simplejson from google.appengine.ext import webapp from google.appengine.ext.webapp import template from google.appengine.ext import db &lt;mycontroller.py&gt; from importheaders import * </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload