executea string

Arjen Dijkstra adijkstra at baandersconsultancy.nl
Tue Feb 22 05:06:03 EST 2005


Groleo Marius wrote:
> 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:

 >>> code.append('funtion ("%s, %s,%s")' % (c, e, s))
 >>> print "\n".join(code) + '\n'
funtion ("2, 3,12")


HTH,

Arjen



More information about the Python-list mailing list