Help with Popen in 2.2

Chris Gonnerman chris.gonnerman at newcenturycomputers.net
Tue Jul 9 01:16:02 EDT 2002


----- Original Message ----- 
From: "Lowel Stern" <ls2311 at netcom.com>


> On Mon, 08 Jul 2002 23:25:45 -0400, Peter Hansen <peter at engcorp.com>
> wrote:
>
> >Please post the code that generates this message.  The code 
> >_can_ be fixed.
> >
> >-Peter
> 
> 
> --------------------------------------
> import os
> key = "%s %s" % ('"stern:STWA"',"1234")
> print key
> fp = os.popen('C:\python_scripts\prog %s') % (key)
> ---------------------------------------

Thar she blows.  The line most likely should be:

    fp = os.popen('C:\python_scripts\prog %s' % key)

Note that the parens after the function or method name
bind "tighter" than the % operator.  The call is made 
FIRST, then the % operation.  It needs to be the other way.

 
> fp = os.popen('C:\python_scripts\prog %s') % (key)
> Traceback (most recent call last):
>   File "<pyshell#6>", line 1, in ?
>     fp = os.popen('C:\python_scripts\prog %s') % (key)
> TypeError: unsupported operand type(s) for %: 'file' and 'str'
> 

Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net
http://newcenturycomputers.net






More information about the Python-list mailing list