How to 'from package import module; from module import variable'? 
Author Message
 How to 'from package import module; from module import variable'?

Hi.  I've recently switched to using packages.  Because I use reload a
lot during testing, it'd be helpful to be able to do this sort of thing
successfully:

Quote:
>>> from mouse.tools import queues
>>> from queues import Cyclic_queue

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named queues

My understanding of the package import routine is still sort of sketchy,
but I was wondering if there's a way to convince the import function
that queues is actually a module it can import from.  I could just make
assignments, but that seems kludgey.

Alex.



Fri, 26 Dec 2003 21:25:32 GMT  
 How to 'from package import module; from module import variable'?

Quote:
> Hi.  I've recently switched to using packages.  Because I use reload a
> lot during testing, it'd be helpful to be able to do this sort of thing
> successfully:

> >>> from mouse.tools import queues
> >>> from queues import Cyclic_queue
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> ImportError: No module named queues

> My understanding of the package import routine is still sort of sketchy,
> but I was wondering if there's a way to convince the import function
> that queues is actually a module it can import from.

from mouse.tools import queues

import sys
sys.modules["queues"] = queues

from queues import Cyclic_queue

Oleg.
----

           Programmers don't die, they just GOSUB without RETURN.



Fri, 26 Dec 2003 21:49:04 GMT  
 How to 'from package import module; from module import variable'?

Ouch, it doesn't use the binding in the current namespace?  OK, I guess
I'll need to write a new __import__ function, or something.

Thanks.
Alex.



Fri, 26 Dec 2003 22:36:45 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. import selected module variables within that module's procedures

2. How to access a module's namespace within the module at import

3. Newbie Help: Dynamic 'import' of modules

4. Importing modules for cgi's

5. Can't import crypt module under Python2.0

6. Pyrity of `from MODULE import *'

7. HELP: odbc module won't import

8. Readl basic probem - can't import shared library modules on Linux

9. Grail won't import dynanimcally linked modules

10. grail can't import module filetypes

11. py2exe doesn't copy imported module to .exe

12. module name errors (trying to import curses functions from modules as needed)

 

 
Powered by phpBB® Forum Software