Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
檀越@新空间
python-demo
提交
289f2d80
P
python-demo
项目概览
檀越@新空间
/
python-demo
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
python-demo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
289f2d80
编写于
6月 21, 2023
作者:
檀越@新空间
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:面向对象
上级
96dc73b7
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
28 addition
and
53 deletion
+28
-53
10_面向对象/05_其它内置方法.py
10_面向对象/05_其它内置方法.py
+0
-7
10_面向对象/08_继承的基础语法.py
10_面向对象/08_继承的基础语法.py
+6
-11
10_面向对象/09_继承_复写和使用父类成员.py
10_面向对象/09_继承_复写和使用父类成员.py
+4
-4
10_面向对象/13_多态.py
10_面向对象/13_多态.py
+0
-1
10_面向对象/数据分析案例/data_define.py
10_面向对象/数据分析案例/data_define.py
+4
-6
10_面向对象/数据分析案例/file_define.py
10_面向对象/数据分析案例/file_define.py
+8
-8
10_面向对象/数据分析案例/main.py
10_面向对象/数据分析案例/main.py
+6
-5
10_面向对象/黑马银行ATM案例/main.py
10_面向对象/黑马银行ATM案例/main.py
+0
-11
data/对象/2011年1月销售数据.txt
data/对象/2011年1月销售数据.txt
+0
-0
data/对象/2011年2月销售数据JSON.txt
data/对象/2011年2月销售数据JSON.txt
+0
-0
未找到文件。
10_面向对象/05_其它内置方法.py
浏览文件 @
289f2d80
...
@@ -28,10 +28,3 @@ class Student:
...
@@ -28,10 +28,3 @@ class Student:
stu1
=
Student
(
"周杰轮"
,
31
)
stu1
=
Student
(
"周杰轮"
,
31
)
stu2
=
Student
(
"林俊节"
,
36
)
stu2
=
Student
(
"林俊节"
,
36
)
print
(
stu1
==
stu2
)
print
(
stu1
==
stu2
)
#
10_面向对象/08_继承的基础语法.py
浏览文件 @
289f2d80
...
@@ -2,19 +2,18 @@
...
@@ -2,19 +2,18 @@
演示面向对象:继承的基础语法
演示面向对象:继承的基础语法
"""
"""
# 演示单继承
# 演示单继承
class
Phone
:
class
Phone
:
IMEI
=
None
# 序列号
IMEI
=
None
# 序列号
producer
=
"ITCAST"
# 厂商
producer
=
"ITCAST"
# 厂商
def
call_by_4g
(
self
):
def
call_by_4g
(
self
):
print
(
"4g通话"
)
print
(
"4g通话"
)
class
Phone2022
(
Phone
):
class
Phone2022
(
Phone
):
face_id
=
"10001"
# 面部识别ID
face_id
=
"10001"
# 面部识别ID
def
call_by_5g
(
self
):
def
call_by_5g
(
self
):
print
(
"2022年新功能:5g通话"
)
print
(
"2022年新功能:5g通话"
)
...
@@ -24,6 +23,8 @@ phone = Phone2022()
...
@@ -24,6 +23,8 @@ phone = Phone2022()
print
(
phone
.
producer
)
print
(
phone
.
producer
)
phone
.
call_by_4g
()
phone
.
call_by_4g
()
phone
.
call_by_5g
()
phone
.
call_by_5g
()
# 演示多继承
# 演示多继承
class
NFCReader
:
class
NFCReader
:
nfc_type
=
"第五代"
nfc_type
=
"第五代"
...
@@ -52,10 +53,4 @@ phone.call_by_4g()
...
@@ -52,10 +53,4 @@ phone.call_by_4g()
phone
.
read_card
()
phone
.
read_card
()
phone
.
write_card
()
phone
.
write_card
()
phone
.
control
()
phone
.
control
()
print
(
phone
.
producer
)
print
(
phone
.
producer
)
# 演示多继承下,父类成员名一致的场景
10_面向对象/09_继承_复写和使用父类成员.py
浏览文件 @
289f2d80
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
class
Phone
:
class
Phone
:
IMEI
=
None
# 序列号
IMEI
=
None
# 序列号
producer
=
"ITCAST"
# 厂商
producer
=
"ITCAST"
# 厂商
def
call_by_5g
(
self
):
def
call_by_5g
(
self
):
print
(
"使用5g网络进行通话"
)
print
(
"使用5g网络进行通话"
)
...
@@ -14,7 +14,7 @@ class Phone:
...
@@ -14,7 +14,7 @@ class Phone:
# 定义子类,复写父类成员
# 定义子类,复写父类成员
class
MyPhone
(
Phone
):
class
MyPhone
(
Phone
):
producer
=
"ITHEIMA"
# 复写父类的成员属性
producer
=
"ITHEIMA"
# 复写父类的成员属性
def
call_by_5g
(
self
):
def
call_by_5g
(
self
):
print
(
"开启CPU单核模式,确保通话的时候省电"
)
print
(
"开启CPU单核模式,确保通话的时候省电"
)
...
@@ -26,9 +26,9 @@ class MyPhone(Phone):
...
@@ -26,9 +26,9 @@ class MyPhone(Phone):
super
().
call_by_5g
()
super
().
call_by_5g
()
print
(
"关闭CPU单核模式,确保性能"
)
print
(
"关闭CPU单核模式,确保性能"
)
phone
=
MyPhone
()
phone
=
MyPhone
()
phone
.
call_by_5g
()
phone
.
call_by_5g
()
print
(
phone
.
producer
)
print
(
phone
.
producer
)
# 在子类中,调用父类成员
# 在子类中,调用父类成员
10_面向对象/13_多态.py
浏览文件 @
289f2d80
...
@@ -75,6 +75,5 @@ def make_cool(ac: AC):
...
@@ -75,6 +75,5 @@ def make_cool(ac: AC):
midea_ac
=
Midea_AC
()
midea_ac
=
Midea_AC
()
gree_ac
=
GREE_AC
()
gree_ac
=
GREE_AC
()
make_cool
(
midea_ac
)
make_cool
(
midea_ac
)
make_cool
(
gree_ac
)
make_cool
(
gree_ac
)
10_面向对象/数据分析案例/data_define.py
浏览文件 @
289f2d80
...
@@ -4,13 +4,11 @@
...
@@ -4,13 +4,11 @@
class
Record
:
class
Record
:
def
__init__
(
self
,
date
,
order_id
,
money
,
province
):
def
__init__
(
self
,
date
,
order_id
,
money
,
province
):
self
.
date
=
date
# 订单日期
self
.
date
=
date
# 订单日期
self
.
order_id
=
order_id
# 订单ID
self
.
order_id
=
order_id
# 订单ID
self
.
money
=
money
# 订单金额
self
.
money
=
money
# 订单金额
self
.
province
=
province
# 销售省份
self
.
province
=
province
# 销售省份
def
__str__
(
self
):
def
__str__
(
self
):
return
f
"
{
self
.
date
}
,
{
self
.
order_id
}
,
{
self
.
money
}
,
{
self
.
province
}
"
return
f
"
{
self
.
date
}
,
{
self
.
order_id
}
,
{
self
.
money
}
,
{
self
.
province
}
"
10_面向对象/数据分析案例/file_define.py
浏览文件 @
289f2d80
...
@@ -17,7 +17,7 @@ class FileReader:
...
@@ -17,7 +17,7 @@ class FileReader:
class
TextFileReader
(
FileReader
):
class
TextFileReader
(
FileReader
):
def
__init__
(
self
,
path
):
def
__init__
(
self
,
path
):
self
.
path
=
path
# 定义成员变量记录文件的路径
self
.
path
=
path
# 定义成员变量记录文件的路径
# 复写(实现抽象方法)父类的方法
# 复写(实现抽象方法)父类的方法
def
read_data
(
self
)
->
list
[
Record
]:
def
read_data
(
self
)
->
list
[
Record
]:
...
@@ -25,7 +25,7 @@ class TextFileReader(FileReader):
...
@@ -25,7 +25,7 @@ class TextFileReader(FileReader):
record_list
:
list
[
Record
]
=
[]
record_list
:
list
[
Record
]
=
[]
for
line
in
f
.
readlines
():
for
line
in
f
.
readlines
():
line
=
line
.
strip
()
# 消除读取到的每一行数据中的\n
line
=
line
.
strip
()
# 消除读取到的每一行数据中的\n
data_list
=
line
.
split
(
","
)
data_list
=
line
.
split
(
","
)
record
=
Record
(
data_list
[
0
],
data_list
[
1
],
int
(
data_list
[
2
]),
data_list
[
3
])
record
=
Record
(
data_list
[
0
],
data_list
[
1
],
int
(
data_list
[
2
]),
data_list
[
3
])
record_list
.
append
(
record
)
record_list
.
append
(
record
)
...
@@ -37,8 +37,7 @@ class TextFileReader(FileReader):
...
@@ -37,8 +37,7 @@ class TextFileReader(FileReader):
class
JsonFileReader
(
FileReader
):
class
JsonFileReader
(
FileReader
):
def
__init__
(
self
,
path
):
def
__init__
(
self
,
path
):
self
.
path
=
path
# 定义成员变量记录文件的路径
self
.
path
=
path
# 定义成员变量记录文件的路径
def
read_data
(
self
)
->
list
[
Record
]:
def
read_data
(
self
)
->
list
[
Record
]:
f
=
open
(
self
.
path
,
"r"
,
encoding
=
"UTF-8"
)
f
=
open
(
self
.
path
,
"r"
,
encoding
=
"UTF-8"
)
...
@@ -54,8 +53,10 @@ class JsonFileReader(FileReader):
...
@@ -54,8 +53,10 @@ class JsonFileReader(FileReader):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
text_file_reader
=
TextFileReader
(
"D:/2011年1月销售数据.txt"
)
text_file_reader
=
TextFileReader
(
json_file_reader
=
JsonFileReader
(
"D:/2011年2月销售数据JSON.txt"
)
"/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
()
list1
=
text_file_reader
.
read_data
()
list2
=
json_file_reader
.
read_data
()
list2
=
json_file_reader
.
read_data
()
...
@@ -63,4 +64,4 @@ if __name__ == '__main__':
...
@@ -63,4 +64,4 @@ if __name__ == '__main__':
print
(
l
)
print
(
l
)
for
l
in
list2
:
for
l
in
list2
:
print
(
l
)
print
(
l
)
\ No newline at end of file
10_面向对象/数据分析案例/main.py
浏览文件 @
289f2d80
...
@@ -13,8 +13,10 @@ from pyecharts.charts import Bar
...
@@ -13,8 +13,10 @@ from pyecharts.charts import Bar
from
pyecharts.options
import
*
from
pyecharts.options
import
*
from
pyecharts.globals
import
ThemeType
from
pyecharts.globals
import
ThemeType
text_file_reader
=
TextFileReader
(
"D:/2011年1月销售数据.txt"
)
text_file_reader
=
TextFileReader
(
json_file_reader
=
JsonFileReader
(
"D:/2011年2月销售数据JSON.txt"
)
"/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
()
jan_data
:
list
[
Record
]
=
text_file_reader
.
read_data
()
feb_data
:
list
[
Record
]
=
json_file_reader
.
read_data
()
feb_data
:
list
[
Record
]
=
json_file_reader
.
read_data
()
...
@@ -34,11 +36,10 @@ for record in all_data:
...
@@ -34,11 +36,10 @@ for record in all_data:
# 可视化图表开发
# 可视化图表开发
bar
=
Bar
(
init_opts
=
InitOpts
(
theme
=
ThemeType
.
LIGHT
))
bar
=
Bar
(
init_opts
=
InitOpts
(
theme
=
ThemeType
.
LIGHT
))
bar
.
add_xaxis
(
list
(
data_dict
.
keys
()))
# 添加x轴的数据
bar
.
add_xaxis
(
list
(
data_dict
.
keys
()))
# 添加x轴的数据
bar
.
add_yaxis
(
"销售额"
,
list
(
data_dict
.
values
()),
label_opts
=
LabelOpts
(
is_show
=
False
))
# 添加了y轴数据
bar
.
add_yaxis
(
"销售额"
,
list
(
data_dict
.
values
()),
label_opts
=
LabelOpts
(
is_show
=
False
))
# 添加了y轴数据
bar
.
set_global_opts
(
bar
.
set_global_opts
(
title_opts
=
TitleOpts
(
title
=
"每日销售额"
)
title_opts
=
TitleOpts
(
title
=
"每日销售额"
)
)
)
bar
.
render
(
"每日销售额柱状图.html"
)
bar
.
render
(
"每日销售额柱状图.html"
)
10_面向对象/黑马银行ATM案例/main.py
已删除
100644 → 0
浏览文件 @
96dc73b7
"""
面向对象,数据分析案例,主业务逻辑代码
实现步骤:
1. 设计一个类,可以完成数据的封装
2. 设计一个抽象类,定义文件读取的相关功能,并使用子类实现具体功能
3. 读取文件,生产数据对象
4. 进行数据需求的逻辑计算(计算每一天的销售额)
5. 通过PyEcharts进行图形绘制
"""
data/对象/2011年1月销售数据.txt
0 → 100644
浏览文件 @
289f2d80
此差异已折叠。
点击以展开。
data/对象/2011年2月销售数据JSON.txt
0 → 100644
浏览文件 @
289f2d80
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录