cmd all commands method?

Gabriel Genellina gagsl-py at yahoo.com.ar
Mon Feb 19 19:02:16 EST 2007


En Mon, 19 Feb 2007 00:08:45 -0300, placid <Bulkan at gmail.com> escribió:

> If anyone can provide a suggestion to replicate the following Tcl
> command in Python, i would greatly appreciate it.
>
> namespace eval foo {
>     variable bar 12345
> }
>
> what this does is create a namespace foo with the variable bar set to
> 12345.

Python namespaces are simple dictionaries. See the eval function.

py> s = "3+x**2"
py> freevars = {"x": 2}
py> eval(s, {}, freevars)
7

-- 
Gabriel Genellina




More information about the Python-list mailing list