[Tutor] Opening a Qt .py file from within another python app
Alan Gauld
alan.gauld at btinternet.com
Thu Mar 22 19:20:27 CET 2012
On 22/03/12 09:57, ken brockman wrote:
> PS Another odd bit, was on the python docs page. It had said that using
> import File_name, without the .py would import it, but not run it. Seems
> a glaring oversight not to have mentioned, what would have made it run.
Actually it does run it when you import, just not the bit after the
if __name__ = "__main__".
The point of modules is that you don't usually want them to run as a
program, you import them so as to get access to the functions within
them. You want to control when they are called from your own code.
So although Python imports do run the file, normally all that happens is
that a few classes and functions get defined and, possibly, a few global
variables get initialized.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list