What is a non-deprecated way to do `new.classobj(name, (base_class,), my_dict)`

前端 未结 1 1411
刺人心
刺人心 2021-01-24 00:20

I found in saucelabs example.py file the following code snippet using the import new module.

import new
# .. snip ..
def on_platforms(p         


        
1条回答
  •  无人共我
    2021-01-24 00:31

    The type keyword is a class. You can perform the above using

    module[name] = type(name, (base_class,), d)
    

    This will return a class of name name with the tuple parameters of the base class base_class, initializing the member objects with the dict d.

    0 讨论(0)
提交回复
热议问题