how to create class variable dynamically in python

You can run the insertion code immediately after a class is created:

class Foo():
     ...

vars=('tx', 'ty', 'tz')  # plus plenty more
for v in vars:
    setattr(Foo, v, 0)

Also, you can dynamically store the variable while the class is being created:

class Bar:
    locals()['tx'] = 'texas'

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)