Joseph Quigley wrote:
 > Well, I'm importing a custom module, and I can't loop back to the module
I imported (the modules are different modes of the program. Someone suggested classes, but I have no idea how to use them.

I'm not sure I understand you, but it sounds like you have two versions of a module and you would like to alternate between them? You could do something like this:


import mymodule_initial as mymodule

mymodule.dosomething()  # calls mymodule_initial .dosomething()

# switch to the other version of mymodule
import mymodule_alternate as mymodule

mymodule.dosomething()  # calls mymodule_alternate.dosomething()

A couple of notes:
- If the import is in a function, declare mymodule as global (I'm not sure this will work, actually; try it and see)
- I would always use qualified names to access mymodule, e.g. mymodule.dosomething(). Don't use
from mymodule_initial import dosomething
there's too much chance for confusion.


You could use a class to do this too but I'm not sure there is an advantage; the module and the class are both serving as namespaces.

Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to