Need Help with str.replace & tuples

M

mikefromvt

Hello.

I am very very unfamiliar with Python and need to update a Python
script. What I need to do is to replace three variables (already
defined in the script) within a string. The present script correctly
replaces two of the three variables. I am unable to add a third
variable. Specifically, I would like to add

"panoble",panoble

to the following code:

idxItemStr+=string.replace(string.replace
(idxItemTplStr,"stylenumber",stylenumber),"formalname",formalname)

and, specifically as regards

idxItemTplStr

Is this possible?

Thanks

Mike
 
B

bearophileHUGS

mikefromvt:
I am very very unfamiliar with Python and need to update a Python
script.  What I need to do is to replace three variables (already
defined in the script) within a string.  The present script correctly
replaces two of the three variables.  I am unable to add a third
variable.  Specifically, I would like to add

"panoble",panoble
to the following code:
idxItemStr+=string.replace(string.replace
(idxItemTplStr,"stylenumber",stylenumber),"formalname",formalname)

This isn't going to win some contest of coding style quality, but you
may try this (for other people: I have not added any new variable name
on purpose):

idxItemStr += idxItemTplStr.replace("stylenumber",
stylenumber).replace("formalname",
formalname).replace("panoble", panoble)

Note that in Python names are usually written like this:
idx_item_tpl
Instead of:
idxItemTplStr

Bye,
bearophile
 
M

mikefromvt

mikefromvt:> I am very very unfamiliar with Python and need to update a Python


(idxItemTplStr,"stylenumber",stylenumber),"formalname",formalname)

This isn't going to win some contest of coding style quality, but you
may try this (for other people: I have not added any new variable name
on purpose):

idxItemStr += idxItemTplStr.replace("stylenumber",
              stylenumber).replace("formalname",
              formalname).replace("panoble", panoble)

Note that in Python names are usually written like this:
idx_item_tpl
Instead of:
idxItemTplStr

Bye,
bearophile

Thank you SO MUCH. It works perfectly.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,291
Messages
2,571,493
Members
48,160
Latest member
KieranKisc

Latest Threads

Top