Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To acheive this you are going to need to do the following things:</p> <ul> <li>Have your code enumerate the source files containing your code.</li> <li>For each source file, import the code specified in the file into a new module.</li> <li>For each module, locate all the classes contained, instantiate each one and add it to your final list.</li> </ul> <p>To take each part in turn:</p> <ul> <li>To enumerate the source files, use <code>os.walk</code> and <code>os.path</code> to find the files and build full paths to the source.</li> <li>To import code from a given source file dynamically, you can do <a href="http://docs.python.org/library/functions.html#execfile" rel="nofollow noreferrer"><code>execfile(my_file) in my_dict</code></a> where <code>my_file</code> is the full path to your source file and <code>my_dict</code> is a dictionary to return the resulting code in (any classes declared in the source file would become members of this dict for example). Note you only need to use this method if the files you are importing are not part of a valid python module/package hierarchy (with an <strong>init</strong>.py file in the package) - if they are you can use <a href="http://docs.python.org/library/functions.html#__import__" rel="nofollow noreferrer"><strong>import</strong>()</a> instead.</li> <li>To enumerate the classes declared in a given module you could use <a href="http://docs.python.org/library/inspect.html#inspect.getmembers" rel="nofollow noreferrer">inspect.getmembers()</a>.</li> </ul>
 

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