Converting string to argument

Brian Jones mojobojo at gmail.com
Thu Jul 1 21:28:22 EDT 2004


This should do what you want:


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

if __name__ == '__main__':
	foo = Foo()
	x_string = "x"
	y_string = "y"

	print getattr(foo, x_string)
	print getattr(foo, y_string)


On Thu, 1 Jul 2004 18:07:16 -0700, Laughlin, Joseph V
<joseph.v.laughlin at boeing.com> 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?
> # Let me know if I need to clarify anything.
> 
> Joe Laughlin
> NCO Simulation Labs
> Integrated Defense Systems
> The Boeing Company
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>




More information about the Python-list mailing list