0

I have a list like this

errlist = ["ERR1", "ERR2"]

I want to create Exception Classes based on the list. This is what i did in errors.py

for e in errlist:
    type(e, (Exception,) {})

My intention is so that I can do this:-

from errors import *
try:
    raise ERR1("testing")
except ERR1 as e:
    do something

How could i achieve that? The method i was doing does not seem to work.

Thanks in advance.

lionel319
  • 1,054
  • 1
  • 17
  • 30
  • You need to assign the return value of `type()` to a name, `type` doesn’t magically create global symbols. – deceze Apr 29 '20 at 07:42
  • Thanks @deceze. is there a way to do something like this? for e in errlist: "ERR1" = type(e, (Exception,) {}) – lionel319 Apr 29 '20 at 07:47

0 Answers0