Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9531757

Browse files
committed
add metaclass
1 parent49220e3 commit9531757

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*[learn python the hardway](http://learnpythonthehardway.org/book/)
2626
*[Python官网教程](https://docs.python.org/2/tutorial/)
2727

28+
###邮件订阅
29+
*[python weekly](http://www.pythonweekly.com/)
2830

2931
#在sublime中运行python
3032
“Preference(首选项)”-----》“Browse Packages(浏览程序包)”----------》“python”,在打开的目录中修改Python.sublime-build文件类似如下

‎meta-class.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/python
2+
#coding:utf-8
3+
4+
# type(name, bases, dict)
5+
# name:class 的名称
6+
# bases:class 的父类,是个 tuple 类型
7+
# dict:class 的 namespace,表现为它的属性
8+
9+
defgreet(self,word='hello'):
10+
printword+',i am '+self.name;
11+
12+
defpersonInit(self,name):
13+
self.name=name;
14+
15+
Person=type('Person', (), {'type':'anim','greet':greet,'__init__':personInit});
16+
17+
p=Person('joel');
18+
p.greet('hi');
19+
20+
# __metaclass__属性
21+
# 创建一个类的时候,可以给它添加 __metaclass__属性
22+
# class Foo(object):
23+
# __metaclass__ = something…
24+
# […]
25+
# 这样做,Python就会使用指定的元类创建Foo类。
26+
27+
# 自定义元类,默认是 type
28+
29+
30+
# 关于python的元类 https://medium.com/leeon-code/python-ca836e7960e2

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp