Re: how to run the main section of another module ?

2009-07-12 Thread Piet van Oostrum
 Stef Mientki stef.mien...@gmail.com (SM) wrote:

SM Stef Mientki wrote:
 hello,
 
 when I''m working in a library,
 and want to test some of the library functions,
 I need to switch to  a main application,
 (which has a normal main-section)
 and run that.
 
 If the library is simply,
 I add a main section to the library,
 so no problem.
 
 But if the library requires a lot of overhead,
 I want to run some main program,
 that has a main section,
 and uses my library under construction.
 
 So how do I call from within the library module,
 in a main section in that library module,
 a main in another module ?
 
 thanks,
 Stef Mientki

SM btw,
SM I just found this in one of my programs (which works but isn't very
SM beautiful)

SM In the library fill under construction I put this main section:
SM (sb_test.py is the main program, that has a main section and uses the
SM library under construction)

SM if __name__ == '__main__':
SMimport db_test
SMnew_globals = {}
SMnew_globals [ '__name__' ] = '__main__'
SMnew_globals [ '__file__' ] = 'not really valuable'
SMexecfile ( 'db_test.py', new_globals )

Why not:

import db_test
db_test.main()

I think that is what Aahz meant.

-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to run the main section of another module ?

2009-07-12 Thread Stef Mientki



SM if __name__ == '__main__':
SMimport db_test
SMnew_globals = {}
SMnew_globals [ '__name__' ] = '__main__'
SMnew_globals [ '__file__' ] = 'not really valuable'
SMexecfile ( 'db_test.py', new_globals )



Why not:

import db_test
db_test.main()

I think that is what Aahz meant.

  

Yes I tried that too,
but it gives the following error:
module object not callable


db_text.__main__()
gives error:
'module' object has no attribute '__main__'

cheers,
Stef

--
http://mail.python.org/mailman/listinfo/python-list


Re: how to run the main section of another module ?

2009-07-12 Thread Aahz
In article mailman.3032.1247422431.8015.python-l...@python.org,
Stef Mientki  stef.mien...@gmail.com wrote:
Stef deleted an attribution:

 Why not:

 import db_test
 db_test.main()
   
Yes I tried that too, but it gives the following error: module object
not callable

You need to create a main() function in db_test first.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur.  --Red Adair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to run the main section of another module ?

2009-07-12 Thread Emile van Sebille

On 7/12/2009 11:13 AM Stef Mientki said...



SM if __name__ == '__main__':
SMimport db_test
SMnew_globals = {}
SMnew_globals [ '__name__' ] = '__main__'
SMnew_globals [ '__file__' ] = 'not really valuable'
SMexecfile ( 'db_test.py', new_globals )



Why not:


implied here is that you restructure...



import db_test
db_test.main()

I think that is what Aahz meant.

  

Yes I tried that too,
but it gives the following error:
module object not callable


db_text.__main__()
gives error:
'module' object has no attribute '__main__'



You see, we're further assuming you've structured the module for this 
purpose.  IOW, your module should end with:


if __name__ == '__main__':
main()

and nothing more.  Then, you can do:

import db_test
db_test.main()

Emile

--
http://mail.python.org/mailman/listinfo/python-list