Can you use string formatting for classes in Python? -


I have to name the classes some things, for example:

  a border (10): Classroom class # "% s" (object):% (num) '' 'class material' '' num + = 1   

My question, is this possible And if not, is there any alternative?

You can use this metaclass (the stuff used to create the square). Example:

  & gt; & Gt; & Gt; Type ('classname', (), {}) & lt; Class' __main __. ClassName '& gt;   

The second argument is a tuple of base classes, the third argument is a dictionary in which the attribute name - & gt; Add attribute value :

  & gt; & Gt; & Gt; CLS = type ('classname', (object,), {'varname': 'var'})> gt; & Gt; & Gt; From Cls.varname 'var'   

to:

With three arguments, return a new type of object. This is essentially a dynamic form of class statement. The name string is the name of the class and the __name___ attribute is created; Base bases determine the base classes and the __ basses __ attribute is created; And the dictionary is the namespace defined for the word class and becomes the __nici __ attribute.


Apart from this Read more for more information.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -