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

Commit 1d6a18b

Browse files
committed
code and pdg
1 parent 437c9e8 commit 1d6a18b

19 files changed

+470
-22
lines changed

‎README.md

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

260260
## [six](content/six.md)
261261

262+
## [traceback](content/traceback.md)
263+
264+
## [code](content/code.md)
265+
262266
## [tools](content/tools.md)
263267

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

‎code/bunch.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ if __name__ == '__main__':
4747
4848
```
4949

50+
快速创建一个对象,当你有一个字典,而需要一个对象的时候,使用 DotDict 是最简单的方式,特别是当你的字典键的数量比较多的时候。
51+
5052
而 bunch 的实现是这样的
5153

5254
```

‎code/card.jpeg

5.34 KB
Loading[フレーム]

‎code/code_terminal.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# doding=utf-8
2+
3+
import code
4+
5+
name = "windard"
6+
7+
# console = code.InteractiveConsole(locals())
8+
# console.interact()
9+
10+
code.interact(local=locals())

‎code/image_background.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
# coding=utf-8
3+
4+
from PIL import Image
5+
6+
im = Image.open('card.jpeg')
7+
r, g, b = im.split()
8+
h,w = im.size
9+
print h,w
10+
11+
# 创建一个新的 r 通道分量, 注意 mode 值为 'L'
12+
# 255 是白
13+
# 0 是黑
14+
n = Image.new('L', (h, w), color=0)
15+
16+
for i in range(h):
17+
for j in range(w):
18+
pixel = im.getpixel((i, j))
19+
if all(map(lambda x:x>210, pixel)):
20+
im.putpixel((i, j), (0, 0, 255))
21+
# im = Image.merge('RGB', (n, n, b))
22+
im.show()
23+

‎code/image_gaussian.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from PIL import Image, ImageFilter
4+
5+
6+
img = Image.open("card.jpeg")
7+
im = img.filter(ImageFilter.GaussianBlur(25))
8+
9+
im.show()

‎code/socket_udp_bind.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,18 @@ def main(host, port):
2020

2121
udpsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
2222
udpsock.bind((host, port))
23-
threading.Thread(target=server, args=(udpsock,)).start()
23+
thread = threading.Thread(target=server, args=(udpsock,))
24+
thread.setDaemon(True)
25+
thread.start()
2426

2527
import pdb
2628
pdb.set_trace()
2729

28-
# while 1:
29-
# data = raw_input(">")
30-
# if not data:
31-
# break
32-
# udpsock.sendto(data, (host, port))
33-
# data, addr = udpsock.recvfrom(bufsize)
34-
# if not data:
35-
# break
36-
# print data
30+
while 1:
31+
data = raw_input(">")
32+
if not data:
33+
break
34+
udpsock.sendto(data, (host, port))
3735

3836
udpsock.close()
3937

‎code/terminal_color.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# coding=utf-8
2+
3+
class bcolors:
4+
BLUE = '033円[95m'
5+
WHITE = '033円[94m'
6+
BLACK = '033円[92m'
7+
GRAY = '033円[93m'
8+
RED = '033円[91m'
9+
ENDC = '033円[0m'
10+
11+
12+
print bcolors.BLUE + "First color is blue " + bcolors.ENDC
13+
print bcolors.WHITE + "Second is white" + bcolors.ENDC
14+
print bcolors.BLACK + "Second is black" + bcolors.ENDC
15+
print bcolors.GRAY + "Second is gray" + bcolors.ENDC
16+
print bcolors.RED + "Second is red" + bcolors.ENDC

‎code/traceback_demo.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# coding=utf-8
2+
import traceback
3+
from flask import Flask
4+
5+
6+
app = Flask(__name__)
7+
8+
9+
@app.route('/')
10+
def index():
11+
traceback.print_stack()
12+
return 'hello world'
13+
14+
15+
def main():
16+
app.run()
17+
18+
19+
if __name__ == '__main__':
20+
main()

‎code/tracestack_flask.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
import signal
3+
import pdb
4+
from flask import Flask
5+
6+
app = Flask(__name__)
7+
signal.signal(signal.SIGUSR2, lambda num,stack: pdb.set_trace())
8+
9+
10+
@app.route('/')
11+
def index():
12+
return json.dumps({"name":"windard"})
13+
14+
15+
def main():
16+
app.run()
17+
18+
19+
if __name__ == '__main__':
20+
data = json.dumps({"name":"windard"})
21+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /