Wednesday 15 January 2014

import - python importing class from python package -


I am using Python in CIG environment and I use MVC design pattern.
So I currently have the following hierarchy:

  main.py mvc / __init__.py model / __init__.py session_initiator.py See / __init__.py controller / __init__.py interface.py < / Code>  

I defined class session_initiator in Session_initiator.py
I am trying to import the session_initiator class inside interface.py
- The following code in the interface is successful:

  Import Model   

But when I try to do anything:

  Model import from session_initiator   

me One meets error This model is not a module.

Please do not refer to sys.path resolution - because I am using an environment where I am unable to edit it.

Thank you.

Edit : All init files are empty.

Edit : I have changed the line to: Model import session_initator from MVC < P> And this line works! But now when you try to:

  self.session_init = session_initiator ()   

I get the following error:

  Type error: 'module' object is not worth the corner    

Do not make names like.

  to .. Model import session_initiator   

In addition, session_initiator is now a module, not a class. If you want to import something from that module inside then you have to do this.

  to .. model.session_initiator import session_initiator    

No comments:

Post a Comment