question regarding Guido's main article
Дамјан Георгиевски
me at here.there.nowhere
Thu Jun 10 08:46:12 EDT 2004
> I implemented a script using the form described in the article. The then
> did:
>
>> python
>>>> execfile("myscript.py")
>
>
> This immediately called my main function, which should have only been
> called if __name__ == "__main__".
Because execfile(), without the two additional parameters, executes your
script in the context of the caller, of the __main__ program.
> What I expect was that __name__ would be something other than __main__ and
> I would be put back at the prompt for instance...
>
>>>> execfile("myscript.py")
>>>> foobar = "foo and a bar"
>>>> main(foobar)
What you need is:
import myscript
foobar = "foo and a bar"
myscript.main(foobar)
--
дамјан
Weird enough for government work.
More information about the Python-list
mailing list