python: How to Create a Python Package

pip install pymssql
pip install pymysql
pip install pyodbc
pip install DBUtils
pip install xlrd
pip install xlwt
pip install xlutils
pip install xlwings
pip install XlsxWriter
pip install openpyxl
pip install pandas
pip install pandasql

pip install win32com
pip install SQLAlchemy
pip install pyspark
pip install pyinstaller 打包执行exe文件的包
pip install pdfplumber pdf
pip install pillow image
win:
Tkinter (自带)
PyQT
WxPython

pip install ttkbootstrap
pip install PyQt5
pip install wxPython

Web:
Django
Tomado
Flask

上篇博文的两个类文件,拖着一个创建好的包名Model中,有些代码会自己生成变化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
"""
StudentScoreInfo.py
学生成绩类
date 2023-06-16
edit: Geovin Du,geovindu, 涂聚文
ide:  PyCharm 2023.1 python 11
"""
import datetime
import sys
import os
 
class StudentScore(object):
    """
    学生成绩类
    """
 
    def __init__(self,ScoreId:int,StudentId:int,CourseId:int,Score:float):
        """
        构造函数(方法)
        :param ScoreId: ID
        :param StudentId:学生ID
        :param CourseId:课程ID
        :param Score:成绩ID
        """
        self._StudentId = StudentId
        self._CourseId = CourseId
        self._Score = Score
        self._ScoreId = ScoreId
 
    '''
    def __del__(self):
        """
 
        :return:
        """
        print(f"{self._StudentId}")
    '''
    def setStudentId(self,StudentId):
        """
 
        :param StudentId:
        :return:
        """
        self._StudentId=StudentId
 
    def getStudentId(self):
        """
 
        :return:
        """
        return self._StudentId
 
    def setCourseId(self,CourseId):
        """
 
        :param CourseId:
        :return:
        """
        self._CourseId=CourseId
 
    def getCourseId(self):
        """
 
        :return:
        """
        return self._CourseId
 
    def setScore(self,Score):
        """
 
        :param Score:
        :return:
        """
        self._Score=Score
 
    def getScore(self):
        """
 
        :return:
        """
        return self._Score
 
    def setScoreId(self,ScoreId):
        """
 
        :param ScoreId:
        :return:
        """
        self._ScoreId=ScoreId
 
    def getScoreId(self):
        """
 
        :return:
        """
        return  self._ScoreId
 
    def __str__(self):
        """
 
        :return:
        """
        return  f"{self._ScoreId},{self._StudentId},{self._Score},{self._CourseId}"
 
 
"""
StudentScoreListInfo.py
学生成绩视图类
date 2023-06-21
edit: Geovin Du,geovindu, 涂聚文
ide:  PyCharm 2023.1 python 11
"""
from Model import StudentScoreInfo
 
 
class StudentScoreList(StudentScoreInfo.StudentScore):  #继承学生成绩实体类,也可以继承多个类
    """
    学生成绩视图类 ,ScoreId:int,StudentId:int,CourseId:int,Score:float,CourseName:str,StudentNO:str,StudentName:str,StudentBirthday:datetime.datetime,Age:int
    ,ScoreId:int,StudentId:int,CourseId:int,Score:float,  ,CourseName:str,StudentNO:str,StudentName:str,StudentBirthday:datetime.datetime,Age:int
    """
    def __init__(self): #,CourseName:str,StudentNO:str,StudentName:str,StudentBirthday:datetime.datetime,Age:int,totalScore:float
        """
 
        :param CourseName:课程名称
        :param StudentNO:学生编号
        :param StudentName:学生姓名
        :param StudentBirthday:出生日期
        :param Age: 年龄
        :param totalScore: 总成绩
        """
        #super().__init__(ScoreId, StudentId,CourseId,Score)
        self._CourseName=""#CourseName
        self._StudentNO=""#StudentNO
        self._StudentName=""#StudentName
        self._StudentBirthday=""#StudentBirthday
        self._Age=0#Age
 
        #self._totalScore =0#totalScore
 
    '''
    def setScoreId(self,ScoreId):
        self._ScoreId=ScoreId
 
    def getScoreId(self):
        return self._ScoreId
 
    def setStudentId(self,StudentId):
        self._StudentId=StudentId
 
    def getStudentId(self):
        return self._StudentId
 
    def setCourseId(self,CourseId):
        self._CourseId=CourseId
 
    def getCourseId(self):
        return self._CourseId
 
    def setScore(self,Score):
        self._Score=Score
 
    def getScore(self):
        return self._Score
 
    '''
    def setCourseName(self,CourseName):
        """
 
        :param CourseName:
        :return:
        """
        self._CourseName=CourseName
 
    def getCourseName(self):
        """
 
        :return:
        """
        return self._CourseName
 
    def setStudentNO(self,StudentNO):
        """
 
        :param StudentNO:
        :return:
        """
        self._StudentNO=StudentNO
 
    def getStudentNO(self):
        """
 
        :return:
        """
        return self._StudentNO
 
    def setStudentName(self,StudentName):
        """
 
        :param StudentName:
        :return:
        """
        self._StudentName=StudentName
 
    def getStudentName(self):
        """
 
        :return:
        """
        return self._StudentName
 
    def setStudentBirthday(self,StudentBirthday):
        """
 
        :param StudentBirthday:
        :return:
        """
        self._StudentBirthday=StudentBirthday
 
    def getStudentBirthday(self):
        """
 
        :return:
        """
        return self._StudentBirthday
 
    def setAge(self,Age):
        """
 
        :param Age:
        :return:
        """
        self._Age=Age
 
    def getAge(self):
        """
 
        :return:
        """
        return self._Age
    '''
    def settotalScore(self,totalScore):
        """
 
        :param totalScore:
        :return:
        """
        self._totalScore=totalScore
 
    def gettotalScore(self):
        """
 
        :return:
        """
        return self._totalScore
    '''
    def __str__(self):
        return f"{self.getScoreId()},{self.getStudentId()},{self.getScore()},{self._StudentNO},{self._StudentName},{self._CourseName},{self._StudentBirthday},{self._Age}"

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"""
 
__init__.py
创建实体类包
date 2023-06-23
edit: Geovin Du,geovindu, 涂聚文
ide:  PyCharm 2023.1 python 11
 
"""
# __init__.py
#from .StudentScoreListInfo import Model  https://www.blog.pythonlibrary.org/2021/09/23/python-101-how-to-create-a-python-package/ 参考无效
#from .StudentScoreInfo import Model
from Model import StudentScoreListInfo
from Model import StudentScoreInfo
 
#StudentScoreInfo.py  参考 Python CookBook 无效
#StudentScoreListInfo.py

  

调用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import Model.StudentScoreListInfo
 
    #1
    #stu=StudentScoreListInfo.StudentScoreList(1,2,1,95,'语文','002','geovindu','2007-08-05',15)
    #print(stu.getStudentName())
    #2
    studens=[]
    stu = Model.StudentScoreListInfo.StudentScoreList()
    stu.setScoreId(1)
    stu.setStudentId(2)
    stu.setCourseId(1)
    stu.setScore(95)
    stu.setCourseName('语文')
    stu.setStudentNO('002')
    stu.setStudentName('geovindu')
    stu.setStudentBirthday('2007-08-05')
    stu.setAge(15)
    studens.append(stu)
    stu = Model.StudentScoreListInfo.StudentScoreList()
    stu.setScoreId(1)
    stu.setStudentId(2)
    stu.setCourseId(1)
    stu.setScore(95)
    stu.setCourseName('语文')
    stu.setStudentNO('002')
    stu.setStudentName('涂聚文')
    stu.setStudentBirthday('2007-08-05')
    stu.setAge(15)
    studens.append(stu)
    for i in studens:
        print(i)

  

输出:

1
2
1,2,95,002,geovindu,语文,2007-08-05,15
1,2,95,002,涂聚文,语文,2007-08-05,15

  

 

 

posted @   ®Geovin Du Dream Park™  阅读(21)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
历史上的今天:
2022-06-23 css: bootstrap accordion
2022-06-23 css: slides container display image
2021-06-23 Easter 复活节(拉丁语:Pascha)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示