May-31-2021, 07:19 PM
(May-31-2021, 03:53 PM)deanhystad Wrote: This starts with a blank class and adds attributes.
class Blank(): pass class NotBlank(): def __init__(self): self.a = 1 self.b = 2.0 self.c = 'three' def only_these_types(types, source_object): blank = Blank() for name, value in source_object.__dict__.items(): if type(value) in types: setattr(blank, name, value) return blank for name, value in only_these_types((int, str), NotBlank()).__dict__.items(): print(name, value)Something like this would only work for a "data class". The new object has none of the method attributes of the source class.
Thanks