restaurant.py模块 内容如下
class Restaurant():
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print(self.restaurant_name.title())
print(self.cuisine_type.title())
def open_restaurant(self):
print("The restaurant is opening!")
新的文件如下
from restaurant import Restaurant #从模块restaurant引入类Restaurant
my_restaurant = Restaurant('youha' , 'Chinese Food')
my_restaurant.describe_restaurant()
my_restaurant.open_restaurant()
结果
Youha
Chinese Food
The restaurant is opening!Process finished with exit code 0