Documentation for importing modules / pythonpath?

Johannes Eble skywalkerpackage at hotmail.com
Fri Feb 21 03:57:14 EST 2003


Hello all,

it seems that I was away from Python for too long. Anyway, if I once
have imported a module and then change the module, then the
interpreter behaves as if I didn't change anything. How can I reimport
modules? I have tried it with ActivePython/PythonWin and with Jython.
In PythonWin it works if I *always* choose the import menu, but this
can't be the right way. For example, I have class A inside A.py and
class B and C inside B.py and C.py respectively, both B and C
extending A. In the main class I use B and C. Then in PythonWin I have
to choose the import menu for A, then for B, then for C, in this
order, before I can execute the main class. Also, in B and C I have to
write the 'import A' (or from A import A) statement. This can't be the
truth?
I didn't find *any* solution to reimport a class in the Jython
console. Shouldn't it be automatic like a makefile i.e. if the date of
the *py is yonger then the date of the *pyc or *class or whatsoever,
then recompile and reimport, otherwise not?

I have searched the documentation, but I couldn't find a solution to
my problem.

Furthermore,
I am used to the Java way to handle the import /classpath issue. I
think the main difference is that Java doesn't have modules, it has
only classes and packages (classes=files=modules if you like it that
way). If you write 'import <package>' and the package is in your
classpath then you can use all the classes of that package. In Python
you have to write 'from <package>.A import A', 'from <package>.B
import B' and so on for all (class) files in the package to get the
same effect. I think that Java is easier to use here if you write only
one class in one file (which I definitely prefer).


Sorry for the lengthy and probably dumb questions, but there is
probably good documentation for this problems.


Best regards


Johannes





More information about the Python-list mailing list