包与模块管理
模块
指令
import
from
importlib.reload(模块)
包
__init__
why
代码重用
命名空间
实现数据或服务共享
步骤
1.找到模块文件
2.编译为字节码
3.运行模块文件
搜索范围
1.程序主目录
2.环境变量
3.标准库
4.扩展库
面向对象
步骤
OOA面向对象分析
OOD面向对象设计
OOP面向对象编程
1. 分析对象
2. 类定义对象代码模板(蓝图)
3. 实例化(内存对象)
实现
1.分析对象的特征行
2.写类描述对象模板
3.实例化,模拟
import datetime
class Book:
def __init__(self,title,price,author,publisher,pubdate):
self.title = title
self.price = price
self.author = author
self.publisher = publisher
self.pubdate = pubdate
def print_info(self):
print('当前这本书的信息如下:')
print('标题:{}'.format(self.title))
print('定价:{}'.format(self.price))
print('作者:{}'.format(self.author))
print('出版社:{}'.format(self.publisher))
print('出版时间:{}'.format(self.pubdate))