crossplatform py2exe - would it be useful?
Thomas Heller
theller at python.net
Thu Aug 7 12:09:47 EDT 2003
Alex Martelli <aleax at aleax.it> writes:
> Thomas Heller wrote:
> ...
>>>> myscript -c "import sys; sys.path.insert(0, sys.executable); import foo"
> ...
>>> Sounds like a good idea to me, if a sensible name is chosen for the
>>> "main module" (I propose 'main':-).
>>
>> My choice would have been __main__ :-) Is it really the correct way to
>> 'import __main__' instead of 'running' it?
>
> Well, most main scripts ARE coded with the "if __name__=='__main__':"
> convention, after all, so an "import __main__" can be seen as a way
> to just piggyback on that existing convention rather than inventing a
> new one in addition. So, I concede it's better than "import main".
>
How would the hook be triggered? The zipimporter code would probably add
argv[0] to sys.path, and then try to 'import __main__' or something like
this. The problem is that a standalone executable python would have to
disable the standard Python command line flags and environment
variables, but they are parse *before* Py_Initialize() is called.
And I hope that the options set by the command line flags and env vars
should now come from the __main__ script itself.
Thomas
More information about the Python-list
mailing list