Help with Popen in 2.2

Peter Hansen peter at engcorp.com
Mon Jul 8 21:07:21 EDT 2002


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?

>>> 'prog "%s" %s' % ('stern:STWA', 1234)
'prog "stern:STWA" 1234'
>>> userpass = 'phansen:secret'
>>> port = 567
>>> 'prog "%s" %s' % (userpass, port)
'prog "phansen:secret" 567'

Does that help any?

-Peter



More information about the Python-list mailing list