Skip to content

Commit 37a249b

Browse files
author
Recursive Lambda God
committed
"Recursive Lambda Refactor V1"
1 parent ca70e62 commit 37a249b

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

python_base.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def func():
416416
function document
417417
"""
418418
print()
419-
class Employee:
419+
class Employee(object):
420420
"""
421421
class document
422422
"""
@@ -807,7 +807,7 @@ def __del__(self): # 函数属性:析构函数
807807
I1 = C1('bob')
808808

809809
#-- Python的类没有基于参数的函数重载
810-
class FirstClass:
810+
class FirstClass(object):
811811
def test(self, string):
812812
print(string)
813813
def test(self): # 此时类中只有一个test函数 即后者test(self) 它覆盖掉前者带参数的test函数
@@ -857,7 +857,7 @@ class A(B):
857857
pass
858858
# OOP和委托: "包装"对象 在Python中委托通常是以"__getattr__"钩子方法实现的, 这个方法会拦截对不存在属性的读取
859859
# 包装类(或者称为代理类)可以使用__getattr__把任意读取转发给被包装的对象
860-
class wrapper:
860+
class wrapper(object):
861861
def __init__(self, object):
862862
self.wrapped = object
863863
def __getattr(self, attrname):
@@ -870,7 +870,7 @@ def __getattr(self, attrname):
870870
list(x.keys()) # 返回 "Trace: keys" ['a', 'b']
871871

872872
#-- 类的伪私有属性:使用__attr
873-
class C1:
873+
class C1(object):
874874
def __init__(self, name):
875875
self.__name = name # 此时类的__name属性为伪私有属性 原理 它会自动变成self._C1__name = name
876876
def __str__(self):
@@ -881,7 +881,7 @@ def __str__(self):
881881
I._C1__name = 'jeey' # 这里可以修改成功 self.name = jeey
882882

883883
#-- 类方法是对象:无绑定类方法对象 / 绑定实例方法对象
884-
class Spam:
884+
class Spam(object):
885885
def doit(self, message):
886886
print(message)
887887
def selfless(message)
@@ -945,7 +945,7 @@ def bar(self, message):
945945
fooChild.bar('HelloWorld')
946946

947947
#-- #实例方法 / 静态方法 / 类方法
948-
class Methods:
948+
class Methods(object):
949949
def imeth(self, x): print(self, x) # 实例方法:传入的是实例和数据,操作的是实例的属性
950950
def smeth(x): print(x) # 静态方法:只传入数据 不传入实例,操作的是类的属性而不是实例的属性
951951
def cmeth(cls, x): print(cls, x) # 类方法:传入的是类对象和数据
@@ -975,13 +975,13 @@ def cmeth(cls, x): print(x)
975975
#-- 类修饰器:是它后边的类的运行时的声明 由@符号以及后边紧跟的"元函数"(metafunction)组成
976976
def decorator(aClass):.....
977977
@decorator
978-
class C:....
978+
class C(object):....
979979
# 等同于:
980-
class C:....
980+
class C(object):....
981981
C = decorator(C)
982982

983983
#-- 限制class属性: __slots__属性
984-
class Student:
984+
class Student(object):
985985
__slots__ = ('name', 'age') # 限制Student及其实例只能拥有name和age属性
986986
# __slots__属性只对当前类起作用, 对其子类不起作用
987987
# __slots__属性能够节省内存

python_metaclass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77

8-
class Foo:
8+
class Foo(object):
99
def hello(self):
1010
print("hello world!")
1111
return

python_version36.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test(a: List[int], b: int) -> int:
2727
primes: List[int] = []
2828
captain: str
2929

30-
class Starship:
30+
class Starship(object):
3131
stats: Dict[str, int] = {}
3232

3333

0 commit comments

Comments
 (0)