Pickle class which create dynamically -
i use py2.7 have read pickle dynamically parameterized sub-class.it places similar question problem more complex.
here more detail code , why use pickle ? or have idea replace apscheduler
i have simplify code.please me. example :
class base(object): base = none # has more method , more params in class def run(self): print self.base class a(base): params = none def run(self): print self.base + self.params class b(base): params = none def run(self): print self.base * self.params def _create(base_class, p): class c(base_class): params = p return c() def factory(base_class): class_list = [] in xrange(0, 500): class_list.append(_create(base_class, i)) return class_list try: import cpickle pickle except importerror: import pickle a_class_list = factory(base_class=a) b_class_lsit = factory(base_class=b) in a_class_list: o = pickle.dumps(a, pickle.highest_protocol) print o
error:
cpickle.picklingerror: can't pickle <class '__main__.c'>: attribute lookup __main__.c failed
Comments
Post a Comment