Importing some functions from a py file

John Machin sjmachin at lexicon.net
Tue Apr 19 23:53:00 EDT 2005


On Tue, 19 Apr 2005 20:17:06 -0700 (PDT), Anthony Liu
<antonyliu2002 at yahoo.com> wrote:

>The choice is (b):
>
>(b) you do have "def main()" as per my example, but
>you have an unguarded "main()" at the top level
>
>Below is exactly what I have:
>
>def func1():
>    do_sth_1()
>
>def func2():
>    do_sth_2()
>
>def main():
>    do sth_m()
>#end of code1.py


If that's what you have, then main() won't be executed *EVER*, neither
when code1 is imported, nor when it is run as a script.

>
>So, you suggest that if I add to the end of code1.py
>module the following,
>
>if __name__ == "__main__":
>    main()
>
>I should be OK, right?
>
>

Maybe, nobody can tell WTF is going on from your descriptions :-( 



More information about the Python-list mailing list