Skip to content

Commit c5ad116

Browse files
author
kangxiaoyu
committed
多重继承
1 parent d652a9f commit c5ad116

File tree

6 files changed

+99
-0
lines changed

6 files changed

+99
-0
lines changed

2017-04-27/oop/MyClass.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/env python
2+
# -*- coding:utf-8 -*-
3+
class MyClass():
4+
x=100
5+
def func(self,name):
6+
return "Hi %s!" % name
7+
def func2(self):
8+
return self.x
9+
if __name__=='__main__':
10+
mc = MyClass()
11+
print mc.x
12+
print mc.func('xiaoqiang')
13+
print mc.func2()
14+

2017-04-27/oop/oop.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
__init__(self,...) 初始化对象,在创建新对象时调用。
2+
__del__(self) 释放对象, 在对象被删除之前调用。
3+
4+
__new__(cls,*args,**kwd)
5+
实例的生成操作,在__init__(self)之前调用
6+
__str__(self) 在使用print 语句时被调用,返回一个字符串。
7+
__getitem__(self,key) 获取序列的索引key对应的值,等价于seq[key]
8+
__len__(self) 在调用内建函数len()时被调用。
9+
__cmp__(str,dst) 比较两个对象src和dst
10+
__getattr__(s,name) 获取属性的值
11+
__setattr__(s,name,value) 设置属性的值
12+
__delattr__(s,name) 删除属性
13+
__gt__(self,other) 判断self对象是否大于other对象。
14+
__lt__(self,other)判断self对象是否小于other对象
15+
__ge__(self, other) 判断 self 对象是否大于或等于 other 对象
16+
__le__(self, other) 判断 self 对象是否小于或等于 other 对象
17+
__eq__(self, other) 判断 self 对象是否等于 other 对象
18+
__call__(self, *args) 把实例对象作为函数调用
19+

2017-04-27/oop/url2.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! /bin/env python3
2+
# -*- coding:utf-8 -*-
3+
from urllib import request
4+
#这是python3的模块 如果有错误,请使用python3运行
5+
with request.urlopen('https://api.douban.com/v2/book/2129650') as f:
6+
data = f.read()
7+
print('Status:', f.status, f.reason)
8+
for k, v in f.getheaders():
9+
print('%s: %s' % (k, v))
10+
print('Data:', data.decode('utf-8'))

kh_api/post_http/post.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
#coding=utf8
3+
4+
import httplib, urllib
5+
6+
httpClient = None
7+
try:
8+
params = urllib.urlencode({'name': 'Maximus', 'addr': "GZ"})
9+
headers = {"Content-type": "application/x-www-form-urlencoded"
10+
, "Accept": "text/plain"}
11+
12+
httpClient = httplib.HTTPConnection("", 80, timeout=30)
13+
httpClient.request("POST", "/test0.html", params, headers)
14+
15+
response = httpClient.getresponse()
16+
print response.status
17+
print response.reason
18+
print response.read()
19+
print response.getheaders() #获取头信息
20+
except Exception, e:
21+
print e
22+
finally:
23+
if httpClient:
24+
httpClient.close()

kh_api/post_http/pythondb.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/env python
2+
# -*- coding:utf-8 -*-
3+
from sqlalchemy import Column, String, create_engine
4+
from sqlalchemy.orm import sessionmaker
5+
from sqlalchemy.ext.declarative import declarative_base
6+
7+
# 创建对象的基类:
8+
Base = declarative_base()
9+
10+
# 定义User对象:
11+
class User(Base):
12+
# 表的名字:
13+
__tablename__ = 'user'
14+
15+
# 表的结构:
16+
id = Column(String(20), primary_key=True)
17+
name = Column(String(20))
18+
19+
# 初始化数据库连接:
20+
engine = create_engine('mysql+mysqlconnector://root:root@localhost:3306/test')
21+
# 创建DBSession类型:
22+
DBSession = sessionmaker(bind=engine)

kh_api/selectCourse.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! /bin/env python3
2+
# -*- coding:utf-8 -*-
3+
from urllib import request
4+
#这是python3的模块 如果有错误,请使用python3运行
5+
with request.urlopen('http://kehai.com/site/ptcourse/ignore/ignore/ignore/ignore/ignore/ignore/100/1/ignore/Topic/ignore/selectCourse.do') as f:
6+
data = f.read()
7+
print('Status:', f.status, f.reason)
8+
for k, v in f.getheaders():
9+
print('%s: %s' % (k, v))
10+
print('Data:', data.decode('utf-8'))

0 commit comments

Comments
 (0)