David Brown wrote:
> On Sat, Aug 30, 2008 at 05:58:18PM -0700, James G. Sack (jim) wrote:
> 
>> ..thus the same problem stands, functionally composing a string (eg, by
>> adding y+z) produces an escape-form I can't seem to eval.
>>
>> I'm really thinking there's something wrong with Python, but thought it
>> might be politic to first check whether there wasn't something wrong
>> with me. :-)
> 
> If you're evaling it, it is expecting a string that contains a python
> expression.  If you want that to be parsed as a string, you'll need to
> have actual quotes in the string:
> 
>   >>> eval("\"\\x41\"")
>   'A'
> 
> Calling eval("x+y") isn't going to be any different than x+y.  It
> isn't going to evaluate the contents of the strings.  Perhaps you
> wanted something like:
> 
>   eval("\"" + x + y + "\"")
> 
>

Oh wow! I did miss that subtlety. Good explanation.

So I wonder if is this the canonical way to do this kind of thing, or is
there a better way?

Regards,
..jim


-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to