Help with Popen in 2.2
Lowel Stern
ls2311 at netcom.com
Mon Jul 8 21:58:08 EDT 2002
On Mon, 08 Jul 2002 21:07:21 -0400, Peter Hansen <peter at engcorp.com>
wrote:
>Lowel Stern wrote:
>>
>> fp = os.popen('prog "stern:STWA" 1234')
>>
>> the above works fine. The quotes must be as shown they may not be
>> changed. The problem is I need to be able to change programatically
>> the section "stren:STWA" and the 1234 section I have not figured a way
>> to do the substitution yet any ideas.
>
>Do you know about the % operator?
>
Yes I do.
>>>> 'prog "%s" %s' % ('stern:STWA', 1234)
>'prog "stern:STWA" 1234'
>>>> userpass = 'phansen:secret'
>>>> port = 567
>>>> 'prog "%s" %s' % (userpass, port)
>'prog "phansen:secret" 567'
You will find that if you use the %s with the popen command you get an
error:
TypeError: unsupported operand type(s) for %: 'file' and 'str'
>
>Does that help any?
>
>-Peter
Still looking for a solution
Lowel
More information about the Python-list
mailing list