ex 6.3
This commit is contained in:
parent
617e409052
commit
18fb6da5ad
5
stock.py
5
stock.py
@ -2,8 +2,6 @@ from structure import Structure
|
||||
|
||||
|
||||
class Stock(Structure):
|
||||
_fields = ('name', 'shares', 'price')
|
||||
|
||||
def __init__(self, name, shares, price):
|
||||
self._init()
|
||||
|
||||
@ -13,3 +11,6 @@ class Stock(Structure):
|
||||
|
||||
def sell(self, nshares):
|
||||
self.shares -= nshares
|
||||
|
||||
|
||||
Stock.set_fields()
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import inspect
|
||||
import sys
|
||||
|
||||
|
||||
@ -20,3 +21,8 @@ class Structure:
|
||||
super().__setattr__(name, value)
|
||||
else:
|
||||
raise AttributeError(f"No attribute {name}")
|
||||
|
||||
@classmethod
|
||||
def set_fields(cls):
|
||||
sig = inspect.signature(cls)
|
||||
cls._fields = tuple(sig.parameters)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user