Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Two things to note here:</p> <ul> <li>In Python, modules are actual objects, and the dot that appears between their names represents an actual attribute access</li> <li>You are doing a relative import, meaning that <code>Source</code> is actually <code>PyModTest.Source</code> (thanks to TokenMacGuy for pointing this out)</li> </ul> <p>So: in order to import <code>PyModTest.Source.WildMod.WildFunc</code>, Python has to</p> <ol> <li>import <code>PyModTest</code> (which was already done by you)</li> <li>check and see if it has an attribute called <code>Source</code>, and if not, create the attribute by importing it from <code>PyModTest/Source/__init__.py</code></li> <li>check and see if that has an attribute called <code>WildMod</code>, and if not, create the attribute by importing it from <code>PyModTest/Source/WildMod.py</code></li> <li>check and see if that has an attribute called <code>WildFunc</code> (which it does)</li> </ol> <p>Some relevant details are discussed in <a href="http://www.python.org/dev/peps/pep-0302/" rel="noreferrer">PEP 302</a> and in the <a href="http://docs.python.org/reference/simple_stmts.html#the-import-statement" rel="noreferrer">Python language reference</a>.</p> <blockquote> <p>Deeper down in the mechanism, a dotted name import is split up by its components. For "<code>import spam.ham</code>", first an "<code>import spam</code>" is done, and only when that succeeds is "<code>ham</code>" imported as a submodule of "<code>spam</code>".</p> </blockquote> <p>If you don't want to have a variable named <code>Source</code>, that's easy to fix: just <code>del Source</code> after you import the function. But bear in mind that it will prevent any code that runs later on from accessing <code>PyModTest.Source.&lt;anything&gt;</code> (except for <code>WildFunc</code>, since you have saved a reference to that). I would definitely suggest just ignoring the reference to <code>Source</code>, not deleting it, since it's not hurting anything.</p>
    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.
 

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