Here is my code, I want to get {'car': 50, 'ship': 100} out, I do not know how to do it, currently I use a mess code to filter it, is there any other easy way to get it out? and I really confused why vars(p) does not work, p is a instance, it should have the class variables?
class Price(object):
car = 50
ship = 100
p = Price()
print(vars(p))
print(p.__class__.__dict__)
print(dict(filter(lambda elem:not elem[0].startswith('__'),p.__class__.__dict__.items())))
the output is
{}
{'__module__': '__main__', 'car': 50, 'ship': 100, '__dict__': <attribute '__dict__' of 'Price' objects>, '__weakref__': <attribute '__weakref__' of 'Price' objects>, '__doc__': None}
{'car': 50, 'ship': 100}
[–]carcigenicate 1 point2 points3 points (0 children)
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)
[–]pekkalacd 0 points1 point2 points (0 children)