Skip to content

Commit 96b8dea

Browse files
committed
Merge branch 'master' of github.com:JustDoPython/python-examples
2 parents 806f1e7 + e56aeea commit 96b8dea

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

Diff for: .DS_Store

0 Bytes
Binary file not shown.

Diff for: xianhuan/.DS_Store

6 KB
Binary file not shown.

Diff for: xianhuan/glob/globstudy.py

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import os
5+
for root,dirs,files in os.walk("/Users/cxhuan/Downloads/globtest/hello"):
6+
for dir in dirs:
7+
print(os.path.join(root, dir))
8+
for file in files:
9+
print(os.path.join(root, file))
10+
11+
import os
12+
files = list()
13+
def dirAll(pathname):
14+
if os.path.exists(pathname):
15+
filelist = os.listdir(pathname)
16+
for f in filelist:
17+
f = os.path.join(pathname, f)
18+
if os.path.isdir(f):
19+
dirAll(f)
20+
else:
21+
dirname = os.path.dirname(f)
22+
baseName = os.path.basename(f)
23+
if dirname.endswith(os.sep):
24+
files.append(dirname+baseName)
25+
else:
26+
files.append(dirname+os.sep+baseName)
27+
28+
dirAll("/Users/cxhuan/Downloads/globtest/hello")
29+
for f in files:
30+
print(f)
31+
32+
import glob
33+
import os
34+
35+
for p in glob.glob('/Users/cxhuan/Downloads/globtest/*'):
36+
print(p)
37+
38+
print('----------------------')
39+
40+
for p in glob.glob('/Users/cxhuan/Downloads/globtest/*/*'):
41+
print(p)
42+
43+
print('----------------------')
44+
45+
for p in glob.glob('/Users/cxhuan/Downloads/globtest/hello/*3.txt'):
46+
print(p)
47+
48+
print('----------------------')
49+
50+
for p in glob.glob('/Users/cxhuan/Downloads/globtest/hello/hello?.txt'):
51+
print(p)
52+
53+
print('----------------------')
54+
55+
for p in glob.glob('/Users/cxhuan/Downloads/globtest/hello/*[0-2].*'):
56+
print(p)
57+
58+
print('----------------------')
59+
60+
p = glob.glob('/Users/cxhuan/Downloads/globtest/hello/hello?.*')
61+
print(p)
62+
63+
print('----------------------')
64+
65+
p = glob.iglob('/Users/cxhuan/Downloads/globtest/hello/hello?.*')
66+
print(p)
67+
print(p.__next__())
68+
print(p.__next__())
69+
70+

Diff for: xianhuan/loguru/logurustudy.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
@author: 闲欢
5+
"""
6+
from loguru import logger
7+
8+
logger.debug('this is a debug message')
9+
10+
logger.add('hello.log')
11+
12+
logger.debug('i am in log file')
13+
14+
id = logger.add('world.log', format="{time} | {level} | {message}", level="INFO")
15+
logger.info('this is a debug message')
16+
logger.remove(id)
17+
logger.info('this is another debug message')
18+
logger.add('runtime.log')
19+
logger.info('this is an debug message')
20+
21+
# 超过200M就新生成一个文件
22+
logger.add("size.log", rotation="200 MB")
23+
# 每天中午12点生成一个新文件
24+
logger.add("time.log", rotation="12:00")
25+
# 一周生成一个新文件
26+
logger.add("size.log", rotation="1 week")
27+
28+
@logger.catch
29+
def a_function(x):
30+
return 1 / x
31+
32+
a_function(0)
33+
34+
35+
36+
def b_function1(x):
37+
try:
38+
return 1 / x
39+
except ZeroDivisionError:
40+
logger.exception("exception!!!")
41+
42+
b_function1(0)

0 commit comments

Comments
 (0)