Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>1) it's nothing but laziness to not prefix your imported names with the module it came from. It's nothing but laziness to not be willing to scroll past the imports to the code. How exactly does having that mess of imports in another file make it any easier to read through? I would leave it in the original file where they are actually used. This <strong>improves</strong> readability because if I need to know where something came from, then I can just go to the top of the file and check it out (using the emacs mark ring to go right back). It also makes it easier to maintain the list because I just have to do a quick search to see where something is used (or not used).</p> <p>2) On my machine, it takes ~812 microseconds to import a module. </p> <pre><code>$ python -mtimeit -s'import os' 'reload(os)' 1000 loops, best of 3: 808 usec per loop </code></pre> <p>This will of course vary greatly with where on your PYTHONPATH it is. If performance is that tight, you might be able to squeeze some out by juggling that around. YMMV.</p> <p>I'm not sure where your coworker is getting the 256kb from. That would depend on the size of the code objects involved.</p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; sys.getsizeof(sys) 24 &gt;&gt;&gt; sys.getsizeof(sys.modules['__main__']) 24 </code></pre> <p>As you can see, the actual module object only takes 24 bytes on my 32 bit machine. I have a feeling that will be system dependent though.</p> <pre><code>&gt;&gt;&gt; def sizeofmodule(mod): ... return sum(sys.getsizeof(getattr(mod, o)) for o in dir(mod)) ... &gt;&gt;&gt; sizeofmodule(itertools) 8662 &gt;&gt;&gt; sizeofmodule(sys) 10275 &gt;&gt;&gt; sizeofmodule(operator) 5230 </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. 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.
 

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