提交 289f2d80 编写于 作者: 檀越@新空间's avatar 檀越@新空间 🐭

fix:面向对象

上级 96dc73b7
......@@ -28,10 +28,3 @@ class Student:
stu1 = Student("周杰轮", 31)
stu2 = Student("林俊节", 36)
print(stu1 == stu2)
#
......@@ -2,12 +2,12 @@
演示面向对象:继承的基础语法
"""
# 演示单继承
class Phone:
IMEI = None # 序列号
producer = "ITCAST" # 厂商
def call_by_4g(self):
print("4g通话")
......@@ -15,7 +15,6 @@ class Phone:
class Phone2022(Phone):
face_id = "10001" # 面部识别ID
def call_by_5g(self):
print("2022年新功能:5g通话")
......@@ -24,6 +23,8 @@ phone = Phone2022()
print(phone.producer)
phone.call_by_4g()
phone.call_by_5g()
# 演示多继承
class NFCReader:
nfc_type = "第五代"
......@@ -52,10 +53,4 @@ phone.call_by_4g()
phone.read_card()
phone.write_card()
phone.control()
print(phone.producer)
# 演示多继承下,父类成员名一致的场景
......@@ -26,9 +26,9 @@ class MyPhone(Phone):
super().call_by_5g()
print("关闭CPU单核模式,确保性能")
phone = MyPhone()
phone.call_by_5g()
print(phone.producer)
# 在子类中,调用父类成员
......@@ -75,6 +75,5 @@ def make_cool(ac: AC):
midea_ac = Midea_AC()
gree_ac = GREE_AC()
make_cool(midea_ac)
make_cool(gree_ac)
......@@ -4,13 +4,11 @@
class Record:
def __init__(self, date, order_id, money, province):
self.date = date # 订单日期
self.order_id = order_id # 订单ID
self.money = money # 订单金额
self.province = province # 销售省份
def __str__(self):
return f"{self.date}, {self.order_id}, {self.money}, {self.province}"
......@@ -39,7 +39,6 @@ class JsonFileReader(FileReader):
def __init__(self, path):
self.path = path # 定义成员变量记录文件的路径
def read_data(self) -> list[Record]:
f = open(self.path, "r", encoding="UTF-8")
......@@ -54,8 +53,10 @@ class JsonFileReader(FileReader):
if __name__ == '__main__':
text_file_reader = TextFileReader("D:/2011年1月销售数据.txt")
json_file_reader = JsonFileReader("D:/2011年2月销售数据JSON.txt")
text_file_reader = TextFileReader(
"/Users/qinyingjie/Documents/idea-workspace/study/python-demo/data/对象/2011年1月销售数据.txt")
json_file_reader = JsonFileReader(
"/Users/qinyingjie/Documents/idea-workspace/study/python-demo/data/对象/2011年2月销售数据JSON.txt")
list1 = text_file_reader.read_data()
list2 = json_file_reader.read_data()
......
......@@ -13,8 +13,10 @@ from pyecharts.charts import Bar
from pyecharts.options import *
from pyecharts.globals import ThemeType
text_file_reader = TextFileReader("D:/2011年1月销售数据.txt")
json_file_reader = JsonFileReader("D:/2011年2月销售数据JSON.txt")
text_file_reader = TextFileReader(
"/Users/qinyingjie/Documents/idea-workspace/study/python-demo/data/对象/2011年1月销售数据.txt")
json_file_reader = JsonFileReader(
"/Users/qinyingjie/Documents/idea-workspace/study/python-demo/data/对象/2011年2月销售数据JSON.txt")
jan_data: list[Record] = text_file_reader.read_data()
feb_data: list[Record] = json_file_reader.read_data()
......@@ -41,4 +43,3 @@ bar.set_global_opts(
)
bar.render("每日销售额柱状图.html")
"""
面向对象,数据分析案例,主业务逻辑代码
实现步骤:
1. 设计一个类,可以完成数据的封装
2. 设计一个抽象类,定义文件读取的相关功能,并使用子类实现具体功能
3. 读取文件,生产数据对象
4. 进行数据需求的逻辑计算(计算每一天的销售额)
5. 通过PyEcharts进行图形绘制
"""
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册