Friday, 15 April 2011

Python module and __all__ -


I am trying to understand how to manage the module with __all . For example, I have a structured code:

  main.py | = & Gt; / Database | = & Gt; __init__.py | = & Gt; Engine (with variable engine, session, etc.)   

I want to be able to import directly session and engine examples Like the database module:

  from the database import session   

I tried to add the line __ All__ = ['Sessions'] or __ all__ = ['engine.session'] to __init__py but when I try to import, one exception to me AttributeError: '

text "itemprop =" text " >

__Ell __ does not list names, by itself, imports items in a module if you database import * to syntax.

import session If you use the database / __ init__ in , then this is the list name to import from that module .gi : from .ignin Import Sessions

No comments:

Post a Comment