Basic 'import' problem

Mel Wilson mwilson at
Sat Feb 7 22:44:56 CET 2004

In article <c03kmp$28u7$1 at>,
Frantisek Fuka <fuka at> wrote:
>My application is started from This file imports many other
>files (modules) that do different stuff. references dozens of
>classes and functions in other modules. After a while, there comes a
>time when some of these modules need to reference some basic function
>inluded in Which means (I thought until now) that I have to
>include in these files. Or not? Are you saying there is no
>chance of doing this? Let's forget "import" for now and please explain
>to me: Is there way to create a Python application consisting of several
>modules that can freely call and reference stuff in each other? From
>your answer it seems that the anwer is "no".

   To evade your problem, design your modules (as much as
you can) as though they were subroutine libraries usable
from any program.

   If you can't do that, maybe pass the main-level functions
as parameters to the lower-level module functions, as

   A really filthy, but workable, last resort would be for
main-level code to poke the necessary function into the
sub-modules namespace, e.g.

        sub1_func1 ():

        import sub1
        def func1 ():
        sub1.main_func = func1

   Another thought, in, define a class with most of
the functionality.  Then, in, define a descendant of
that class with its own special method to perform the
main-level operation.

        Good Luck.      Mel.

More information about the Python-list mailing list