Neil Schemenauer wrote:
Jason Orendorff wrote:
The substitution only happens once.
My example was not well thought out. I was thinking something more like:
secret_key = "spam" user = "joe" x = "$user said: " + raw_input() print $x
That wouldn't work either since $ only evaluates literals. Amazing what you learn by actually reading the PEP. Yes, I'm an idiot.
Sorry, I haven't followed this thread real closely, but I thought someone said eval() was used under the covers. If x is eval'ed and the string is as above, I get the following in 2.1: >>> secret_key = 'spam' >>> x = raw_input('? ') ? eval("secret_key") # Is the following commented print equivalent the the line below it? ### print "You entered $x" >>> print "You entered", eval(x) You entered spam >>> print "You entered %(x)s" % locals() You entered eval("secret_key") Not sure if that's the same as what you are talking about though. Neal