dynamic creating of class

Jarosław Zabiełło webmaster at watchtowerDOTcom.pl
Sat Jun 21 08:29:02 EDT 2003


Is there a possibility for Python to dynamic binding of class?  I can
do it in PHP but I do not know how to make the same in Python. 
Look at the following example:

#PHP:
<?php
class A {
    var $x = 'class A';
}
class B {
    var $x = 'class B';
}
$kind = 'B';
$run = new $kind(); # IT WORKS!
print $run->x;
?>

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




More information about the Python-list mailing list