Help with Popen in 2.2

Lowel Stern ls2311 at netcom.com
Tue Jul 9 01:57:42 EDT 2002


On Tue, 9 Jul 2002 00:16:02 -0500, "Chris Gonnerman"
<chris.gonnerman at newcenturycomputers.net> wrote:

>----- 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
>
>
Thank you all for your input and for fixing this problem for me.

Lowel






More information about the Python-list mailing list