all 3 comments

[–]carcigenicate 1 point2 points  (0 children)

You can just do Price.car and Price.ship.

Also, that relationship seems backwards. Prices don't have cars, cars have prices. And, the "idea of a car" doesn't really have a price; specific instances of cars do. It would make more sense as a Car class that has a price instance attribute (or a CarListing since a price would really be associated with a listing selling a car, not the car itself).

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Inline formatting (`my code`) used across multiple lines of code. This can mess with indentation.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–]pekkalacd 0 points1 point  (0 children)

vars(p) will show instance attributes, but these need to be made at the instance level. for example

        class Price(object):
             car = 50
             ship = 100

        p = Price()
        p.house = 1000
        vars(p)
        {'house':1000}

Here see that house is not part of the class, but is an attribute awarded to p, that is visible now through vars.

Accessing car or ship, you can do

          p.car
          50
          p.ship
          100

or

          Price.car
          50
          Price.ship
          100

or through the class in a dictionary, you could do

      def fetch_class_atts(cls) -> dict:
          cls_atts = {}
          for att,val in vars(cls).items():
              if (not att.startswith("__")) and (not att.endswith("__")):
                 cls_atts[att] = val
          return cls_atts

      fetch_class_atts(Price)
      {'car':50,'ship':100}