0

I need a Python http://legacy.python.org/dev/peps/pep-0302/ finder and importer class which works on a specific directory, but it can load only .py files (i.e. no .so, no .dll, no .pyc).

The specified directory contains several packages (with __path__ specified and overridden from the default __path__ added for __init__.py).

Also I need a loader which doesn't create .pyc files, and doesn't use any of the Python 2.6-specific solutions (e.g. sys.dont_write_bytecode = True, python -B or PYTHONDONTWRITEBYTECODE).

2
  • You could always load the files and use compile()/exec directly.
    – mdurant
    Oct 12, 2014 at 14:01
  • I know about compile and exec, but the modules I want to load have complicated inter-dependencies (they are importing hundreds of each other), and I'd like to get exactly the same import filename resolution as Python has, but without loading any non-.py files.
    – pts
    Oct 12, 2014 at 14:05

1 Answer 1

0

Since I couldn't find an existing implementation, I wrote one: https://github.com/pts/import_only_py/blob/master/import_only_py.py

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.