executea string

G

Groleo Marius

I have the folowing code:
c=2
e=3
s="12"
code.append('funtion ("c, e,s")')
print "\n".join(code) + '\n'

The problem is when i call append.
The variables s, c, e are not replaced with their value, so in the end
i get the result:

funtion(" c, e, s");

The result that i want is :
funtion("2,3,12");



--
Regards,
.''`. # touch universe
: :' : # chmod +rwx universe
`. `'` # ./universe
`- Debian - when you have better things to do than fix a system
 
A

Arjen Dijkstra

Groleo said:
I have the folowing code:
c=2
e=3
s="12"
code.append('funtion ("c, e,s")')
print "\n".join(code) + '\n'

The problem is when i call append.
The variables s, c, e are not replaced with their value, so in the end
i get the result:

funtion(" c, e, s");

The result that i want is :
funtion("2,3,12");

I don't know exactly what you want, but try this:
funtion ("2, 3,12")


HTH,

Arjen
 
C

Cyril BAZIN

c=2
Hello,

You could try this:

-----------------------
from string import Template
code = ""
c=2
e=3
s="12"
code.append(Template('function ("$c, $e, $s")').substitute(vars()))
print "\n".join(code) + '\n'
------------------------

For more informations about templates, see:
http://docs.python.org/lib/node105.html
Note that is new in version 2.4...


Cyril
 

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

Forum statistics

Threads
474,221
Messages
2,571,131
Members
47,747
Latest member
swapote

Latest Threads

Top