dynamic creating of class

Martin v. Löwis martin at v.loewis.de
Sat Jun 21 08:53:48 EDT 2003


Jarosław Zabiełło <webmaster at watchtowerDOTcom.pl> writes:

> #Python:
> class A:
> 	x = 'class A'
> class B:
> 	x = 'class B'
> kind = 'B'
> run = kind() # IS DOES NOT WORK :(
> print run.x

Try

class A:
	x = 'class A'
class B:
	x = 'class B'
kind = B
run = kind()
print run.x

instead. Classes are objects in Python, and can be assigned to
variables.

HTH,
Martin





More information about the Python-list mailing list