Monday, 15 June 2015

import - how to reference python package when filename contains a period -


I am using django and I have a model named models. Admin.py and I want to model the following ideas. However, I get a syntax error for double quotation marks: Py:

ad.example.com.

But if I do not just give any modules by name of the models then I get "importError: Module named Administrator"

What to import from a Python file Is the way (there is a duration of its name)?

Basically, you can a module with an invalid name Import But you have to use it for, eg Assuming that the file has been named models.admin.py , you can

  import with import ('models.admin.py', 'Rb') as FP: Models_admin = imp.load_module ('models_admin', fp, 'models.admin.py', ('.py', 'rb', imp.PY_SOURCE))  

But read the docs and before you start using it.


No comments:

Post a Comment