wow yoo wow yoo - 1 year ago 66
Python Question

Do modules have types in Python?

I'm reading PEP338 .Some words confused me:

If the module is found, and is of type PY_SOURCE or PY_COMPILED , then the command line is effectively reinterpreted from
python <options> -m <module> <args>
python <options> <filename> <args>

Do modules have types in Python?

Answer Source

Modules can be loaded from different sources. The author refers to 2 specific sources the module was loaded from, see the imp module documentation:

The module was found as a source file.


The module was found as a compiled code object file.


The module was found as dynamically loadable shared library.

These values are used in the return value of the imp.get_suffixes() function, among others.

The PEP states that only modules loaded from source (.py files) and from a bytecode cache file (.pyc) are supported; the -m switch does not support C extension modules (typically .so or .dll dynamically loaded libraries).

The resulting module object is still just a module object; the word type in the text you found is not referring Python's type system.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download