Py2Exe and sys.argv : The Lost Arguments

Larry Bates larry.bates at websafe.com
Thu Aug 17 17:06:14 EDT 2006


I entered the following simple program, compiled with py2exe (2.4)
and ran it the way you describe with two files selected and it
did what you said (e.g. only shows ays.argv[0] and sys.argv[1]):

import sys
print sys.argv
x=raw_input('Press return to continue')

Under 2.5 it didn't work at all (not sure why).

Funny thing is that if I select two .txt files and do a Open With
Notepad, Explorer only opens one of them.  So I think it is
Explorer that is throwing away the extra arguments.  Otherwise
I would expect it to open multiple notepad instances.

-Larry Bates


Thomas W wrote:
> I've created a simple script like so :
> 
> import sys
> import wx
> 
> app = wx.PySimpleApp()
> dlg = wx.MessageDialog(None, "%s" % sys.argv, 'A Message Box',
> wx.YES_NO | wx.ICON_QUESTION)
> retCode = dlg.ShowModal()
> app.MainLoop()
> 
> If I run this on the command line like
> python testcmd.py <path-to>/somefile.ext <path-to>/anotherfile.ext
> 
> it displays a messagebox with a stringformatted list containing
> testcmd.py, somefile.ext and anotherfile.ext.
> 
> Then I "compile" the script using py2exe, generate a file called
> testcmd.exe and select the same two files in Explorer, right click,
> "Open with ...", browse to testcmd.exe and proceed. Now the dialogbox
> only shows two items in the list; testcmd.exe and one of the files I
> selected. Why?
> 
> Is it impossible to compile a script using py2exe and pass selected
> items in Explorer to my script? It works fine when called on the
> command line so it might be something related to Explorer but I'm
> completly lost.
> 



More information about the Python-list mailing list