Skip to content

Commit 2494b77

Browse files
committed
add cprofile
1 parent a5c239e commit 2494b77

File tree

6 files changed

+56
-4
lines changed

6 files changed

+56
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ python的强大之处有很大的一方面在于它有各种各样非常强大
253253

254254
## [halo](content/halo.md)
255255

256+
## [cProfile](content/cProfile.md)
257+
256258
## [tools](content/tools.md)
257259

258260
## [Other_thing](content/other_thing.md)

code/redis_zset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
print r.zrank('name', 'lily')
2020

2121
# 查看所有元素,并显示分数
22-
print r.zrange('name', 0, -1, True)
22+
print r.zrange('name', 0, -1, withscores=True)
2323

2424
# 查看分数在 2-4 之间的元素
2525
print r.zrangebyscore('name', 2, 4)

content/cProfile.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## cProfile
2+
3+
性能检测工具
4+
5+
可以用来计算耗时
6+
7+
```
8+
import cProfile
9+
import re
10+
cProfile.run('re.compile("foo|bar")')
11+
```

content/logging.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,33 @@ logger.addHandler(stream_handler)
101101
102102
logger.setLevel(logging.DEBUG)
103103
```
104+
105+
也可以这样配置日志
106+
107+
```
108+
import logging
109+
110+
def main():
111+
# Configure the logging system
112+
logging.basicConfig(
113+
filename='app.log',
114+
level=logging.ERROR,
115+
format='%(levelname)s:%(asctime)s:%(message)s'
116+
)
117+
118+
# Variables (to make the calls that follow work)
119+
hostname = 'www.python.org'
120+
item = 'spam'
121+
filename = 'data.csv'
122+
mode = 'r'
123+
124+
# Example logging calls (insert into your program)
125+
logging.critical('Host %s unknown', hostname)
126+
logging.error("Couldn't find %r", item)
127+
logging.warning('Feature is deprecated')
128+
logging.info('Opening file %r, mode=%r', filename, mode)
129+
logging.debug('Got here')
130+
131+
if __name__ == '__main__':
132+
main()
133+
```

content/redis.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ print r.zrange('name', 0, -1)
286286
print r.zrank('name', 'lily')
287287
288288
# 查看所有元素,并显示分数
289-
print r.zrange('name', 0, -1, True)
289+
print r.zrange('name', 0, -1, withscores=True)
290290
291291
# 查看分数在 2-4 之间的元素
292292
print r.zrangebyscore('name', 2, 4)
@@ -319,7 +319,7 @@ print r.zrange('name', 0, -1)
319319
```
320320
['mary', 'john', 'lily', 'heny']
321321
2
322-
['heny', 'lily', 'john', 'mary']
322+
[('mary', 1.1), ('john', 2.2), ('lily', 3.3), ('heny', 4.4)]
323323
['john', 'lily']
324324
4
325325
2

content/webbrowser.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,13 @@ True
1414
True
1515
```
1616

17-
虽说写的浏览器是 IE ,但是打开的还是我的 chrome ,而且后面的三个函数的效果一模一样。
17+
虽说写的浏览器是 IE ,但是打开的还是我的 chrome ,而且后面的三个函数的效果一模一样。
18+
19+
> 其实应该是不一样的,一个是打开新的标签页,一个是打开新的浏览器窗口
20+
21+
也可以选定浏览器打开
22+
23+
```
24+
>>> a = webbrowser.get('safari')
25+
>>> a.open('https://baidu.com')
26+
```

0 commit comments

Comments
 (0)