python: How to Create a Python Package

"""
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}"



"""
 
__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

调用:

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,95,002,geovindu,语文,2007-08-05,15
1,2,95,002,涂聚文,语文,2007-08-05,15

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值