Use ole if __name__ == "__main__":
Vehicle.py
class Vehicle:
def __init__(self, brand, model):
self.brand = brand
self.model = model
def show_description(self):
print('Brand: ', self.brand, 'Model: ', self.model)
if __name__ == "__main__":
volvo = Vehicle('Volvo','L350H')
volvo.show_description()
Excavator.py
from Vehicle import Vehicle
class Excavator(Vehicle):
def __init__(self, brand, model):
super.__init__(brand, model)
if __name__ == "__main__":
hitachi = Excavator('Hitachi','EX8000')
hitachi.show_description()
This way, if you run either module it will only output what is defined in the if __name__ == "__main__":
section.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…