On 01/18/2010 09:26 AM, mdipierro wrote:
do you have an empty __init__.py file in odt/ ? If not that is
necessary.

Yes, otherwise I would not be able to import dispatcher at all.

Is there a variable called __all__ in dispatcher.py? It should be a
list of variable that can be exported and should include RPATH2

No, it should not be necessary for me to use __all__ because:

  - RPATH2 is not an underscored variable (not __RPATH2__)
  - I'm importing RPATH2 explicitly, with no wildcard:
       from odt.dispatcher import RPATH2
    not:
       from odt.dispatcher import *

Incidentally dispatcher is my own code.  I'm just using it
as an example that I can modify the module, but importing
a newly defined item will fail until I restart the server.

  1. odt.dispatcher.py:  RPATH1 = 'test one'
  2. controller.py:  from odt.dispatcher import RPATH1
  3. start web2py
  4. works
  5. add to odt.dispatcher.py:  RPATH2 = 'test two'
  6. controller.py:  from odt.dispatcher import RPATH2
  6. next request generates import exception
  7. restart web2py
  8. works, RPATH2 successfully imported

Exposing external imports using __all__ would be more
tedious than simply restarting the server.

-Jeff



On Jan 17, 11:32 pm, Jeff Bauer<jba...@rubic.com>  wrote:
I've got an external module /odt/dispatcher.py, with
a class defined:

class Dispatcher:
      pass

I can import Dispatcher into controllers/default.py.
However, if I edit dispatcher.py to add a new element
while the web2py server is running and attempt to
import it ...

RPATH2 = "411"

... web2py throws an exception:

Traceback (most recent call last):
    File "web2py/gluon/restricted.py", line 173, in restricted
      exec ccode in environment
    File "web2py/applications/oprep/controllers/default.py", line 3, in
<module>
      from odt.dispatcher import RPATH2
ImportError: cannot import name RPATH2

Once I've shut down the server and restarted, everything's
fine and RPATH2 can be readily imported into the default.py
controller.

Interesting.

--
Jeff Bauer
Rubicon, Inc.
-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.


Reply via email to