Skip to content

Commit ad322ad

Browse files
author
bajins
committed
feat: 添加多个示例脚本
- 新增 class_example.py: 演示 Python 类的使用 - 新增 compress.py: 提供各种压缩算法的示例 - 新增 datetime_example.py: 演示日期和时间操作 - 新增 file_example.py: 展示文件操作示例 - 新增 html2pdf_flask/app.py: 实现一个将 HTML 转换为 PDF 的 Flask 应用
1 parent 73fe4aa commit ad322ad

File tree

11 files changed

+1369
-0
lines changed

11 files changed

+1369
-0
lines changed

class_example.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
#
4+
# @Description:
5+
# @PreInstall:
6+
# @Author : https://www.bajins.com
7+
# @File : class_example.py
8+
# @Version: 1.0.0
9+
# @Time : 2021/9/7 15:07
10+
# @Project: python_learning
11+
# @Package:
12+
# @Software: PyCharm
13+
14+
15+
# self和cls的区别不是强制的,只是PEP8中一种编程风格,slef通常用作实例方法的第一参数,cls通常用作类方法的第一参数
16+
class A(object):
17+
def foo(self, x):
18+
print("executing foo(%s,%s)" % (self, x))
19+
print('self:', self)
20+
21+
@classmethod
22+
def class_foo(cls, x):
23+
print("executing class_foo(%s,%s)" % (cls, x))
24+
print('cls:', cls)
25+
26+
@staticmethod # 与普通函数相同
27+
def static_foo(x):
28+
print("executing static_foo(%s)" % x)
29+
30+
31+
if __name__ == '__main__':
32+
print(dir(A())) # 查看所有属性和方法,包含继承的object类内建属性和方法
33+
g = globals() # 查看所有全局变量
34+
print(g)
35+
print(g['__builtins__'].__dict__)

0 commit comments

Comments
 (0)