Migrating from PHP to Python... (fwd)

Lulu of the Lotus-Eaters mertz at gnosis.cx
Sun Sep 2 21:52:55 EDT 2001


"Rick Shin" <rick at slaveware.com> wrote:
|Actually, I was referring to PHP's ability to assign names dynamically to
|variables. For example:
|$var = 'hello';
|$$var = 'world!';
|echo $var . ' ' . $$var;    // prints 'hello world!'
|echo $var . ' ' . $hello;    // prints 'hello world!' too

Although the below is rarely very Pythonic, you can lean on the 'eval()'
function and 'exec' statement to get the same "variable variables" as
PHP:

    >>> var = 'hello'
    >>> exec var+'="world!"'
    >>> print var, eval(var)
    hello world!
    >>> print var, hello
    hello world!

Yours, Lulu...




More information about the Python-list mailing list