Skip to content
Advertisement

Tag: python-class

Python dataclass, one attribute referencing other

Can a dataclass attribute access to the other one? In the above example, one can create a Stock by providing a symbol and the price. If price is not provided, it defaults to a price which we get from some function get_price. Is there a way to reference symbol? This example generates error NameError: name ‘symbol’ is not defined. Answer

Advertisement