0

abc.py, how to create b() in class a ?

class a(object):
  bInst=b()

def start():
  class b(obj):
    pass

if __name=='__main__'
  start()

But how to using variable, Here is the codes, it report 'myCls' is not defined.

class a(obj):
   inst=myCls()

def start
    tSuiteN="myCls"
    exec('global tSuiteN')
    str="class {}(object): pass".format(tSuiteN)
    exec(str)
brike
  • 313
  • 4
  • 10

1 Answers1

3

Make it global.

def start():
  global b
  class b(obj):
    pass
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358