crossplatform py2exe - would it be useful?
aleax at aleax.it
Thu Aug 7 20:29:44 CEST 2003
Thomas Heller wrote:
> Alex Martelli <aleax at aleax.it> writes:
>> Thomas Heller wrote:
>>>>> myscript -c "import sys; sys.path.insert(0, sys.executable); import
>>>> 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 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.
Ah, yes, good point. So, the executable needs to know whether to do
the usual commandline and environment processing, or not, _before_
calling Py_Inizialize. One approach might be to trigger this based
on the executable's own *name* -- do the full commandline and environment
processing if and only if the executable's name starts with (case-
insensitive, probably, to be safe...) the six letters 'python', but
not otherwise. There are, no doubt, other alternative ways, too, but
this one seems dirt-simple and practically sufficient.
> And I hope that the options set by the command line flags and env vars
> should now come from the __main__ script itself.
I'm not sure I understand what you mean. Anyway, I do see that if
my 'foobar.exe' is a python.exe + appended zipfile, then running
'foobar -i' should just put '-i' in sys.argv, and NOT gobble it up
to mean "enter interactive mode", for example.
More information about the Python-list