Converting string to argument

Tobiah toby.nospam at rcsreg.com
Fri Jul 2 15:29:45 EDT 2004


What you really want is this:

class Foo:
         x = "blah"
         y = "blah some more"


foo = Foo()

x_string = 'x'
y_string = 'y'

print eval('foo.' + x_string)
print eval('foo.' + y_string)





Laughlin, Joseph V wrote:
> 
> class Foo:
> 	x = "blah"
> 	y = "blah some more"
> 
> foo = Foo()
> x_string = "x"
> y_string = "y"
> 
> # I want something like this to work:
> print foo.x_string
> print foo.y_string
> # The above should print out "blah" and "blah some more"
> # Any ideas?






More information about the Python-list mailing list