Re: Importing some functions from a py file

2005-04-19 Thread Anthony Liu
O, sorry, I did have main() at the very end of code1.py. Sorry for this confusion. --- John Machin <[EMAIL PROTECTED]> wrote: > On Tue, 19 Apr 2005 20:17:06 -0700 (PDT), Anthony > Liu > <[EMAIL PROTECTED]> wrote: > > >The choice is (b): > > > >(b) you do have "def main()" as per my example, b

Re: Importing some functions from a py file

2005-04-19 Thread John Machin
On Tue, 19 Apr 2005 20:17:06 -0700 (PDT), Anthony Liu <[EMAIL PROTECTED]> 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_

Re: Importing some functions from a py file

2005-04-19 Thread Anthony Liu
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 So, you suggest that if I add to the end of

Re: Importing some functions from a py file

2005-04-19 Thread John Machin
On Tue, 19 Apr 2005 19:13:13 -0700 (PDT), Anthony Liu <[EMAIL PROTECTED]> wrote: >I think I got confused by the python import facility. >Say, in code1.py I have func1, func2, func3 and main. >In code2.py, I *only* want to use func2 from code1.py. >So, I did > >from code1 import func2 > >But every t

Re: Importing some functions from a py file

2005-04-19 Thread Anthony Liu
Hmm,thanks a lot. I still don't quite get it. So, instead of defining a main like def main(): do things here I should do something like below in both modules? if __name__ == "__main__": call the functions you defined here. --- Michael Soulier <[EMAIL PROTECTED]> wrote: > On 4/19/05,

Re: Importing some functions from a py file

2005-04-19 Thread Michael Soulier
On 4/19/05, Anthony Liu <[EMAIL PROTECTED]> wrote: > > You are certainly right, because I don't know how to > protect the main functions. Where do I put > > if __name__ == '__main__': main() I just glanced in the modules section of the python documentation and surprisingly this is not mentioned

Re: Importing some functions from a py file

2005-04-19 Thread Anthony Liu
--- Michael Soulier <[EMAIL PROTECTED]> wrote: > On 4/19/05, Anthony Liu <[EMAIL PROTECTED]> > wrote: > > But every time, I run code2.py, the main() of > code1.py > > is run. > > You probably did not protect your main function in > both modules. > > ie. > > if __name__ == '__main__': main() >

Re: Importing some functions from a py file

2005-04-19 Thread Michael Soulier
On 4/19/05, Anthony Liu <[EMAIL PROTECTED]> wrote: > But every time, I run code2.py, the main() of code1.py > is run. You probably did not protect your main function in both modules. ie. if __name__ == '__main__': main() Mike -- Michael P. Soulier <[EMAIL PROTECTED]> http://www.digitaltorqu