Skip to content

Commit d27e294

Browse files
feat learn shortuuid and prettytable
1 parent e4eb08f commit d27e294

File tree

24 files changed

+184
-16
lines changed

24 files changed

+184
-16
lines changed

acrobatics/bar_chart_race/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ bar_chart_race,Send email in Python conveniently for mail using bar_chart_race
66

77
### Used by pyenv virtualenv bar_chart_race
88

9-
工具
109
pyenv virtualenv 3.10.9 bar_chart_race
1110
pyenv activate bar_chart_race
1211
python -m pip install --upgrade pip

acrobatics/emoji/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ emoji,Send email in Python conveniently for mail using emoji
66

77
### Used by pyenv virtualenv emoji
88

9-
工具
109
pyenv virtualenv 3.10.9 emoji
1110
pyenv activate emoji
1211
python -m pip install --upgrade pip

acrobatics/prettytable/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# prettytable
2+
3+
prettytable,Display data in a visually appealing ASCII table format
4+
5+
## use
6+
7+
### Used by pyenv virtualenv prettytable
8+
9+
pyenv virtualenv 3.10.9 prettytable
10+
pyenv activate prettytable
11+
python -m pip install --upgrade pip
12+
cd acrobatics/prettytable
13+
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
14+
15+
### Related documents
16+
17+
prettytable: https://github.com/jazzband/prettytable
18+
19+
## uninstall
20+
21+
pyenv virtualenv-delete prettytable
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from re import T
2+
from prettytable import PrettyTable, from_csv
3+
import prettytable
4+
5+
6+
print(
7+
"---------------------------------base useage---------------------------------------"
8+
)
9+
x = PrettyTable(["City name", "Area", "Population", "Annual Rainfall"])
10+
11+
x.add_row(["Adelaide", 1295, 1158259, 600.5])
12+
x.add_row(["Brisbane", 5905, 1857594, 1146.4])
13+
x.add_row(["Darwin", 112, 120900, 1714.7])
14+
x.add_row(["Hobart", 1357, 205556, 619.5])
15+
x.add_row(["Sydney", 2058, 4336374, 1214.8])
16+
x.add_row(["Melbourne", 1566, 3806092, 646.9])
17+
x.add_row(["Perth", 5386, 1554769, 869.4])
18+
19+
x.add_column("additional_column", ["1"] * 7)
20+
21+
print(x)
22+
23+
print(
24+
"---------------------------------get specify position---------------------------------------"
25+
)
26+
print(x.get_string(fields=["City name"], start=1, end=3))
27+
28+
print(
29+
"-----------------------------------------sort-----------------------------------------------"
30+
)
31+
print(x.get_string(sortby="Population", reversesort=True))
32+
33+
34+
print(
35+
"-----------------------------------------set alignment-----------------------------------------------"
36+
)
37+
# l代表左对齐,c代表居中,r代表右对齐
38+
x.align["additional_column"] = "l"
39+
x.align["Area"] = "c"
40+
x.align["Annual Rainfall"] = "r"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from prettytable import from_csv
2+
3+
4+
print(
5+
"\n---------------------------------read from csv---------------------------------------\n"
6+
)
7+
with open("./test.csv") as f:
8+
tb = from_csv(f)
9+
print(tb)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from prettytable import PrettyTable
2+
import prettytable
3+
4+
x = PrettyTable(["City name", "Area", "Population", "Annual Rainfall"])
5+
6+
x.add_row(["Adelaide", 1295, 1158259, 600.5])
7+
x.add_row(["Brisbane", 5905, 1857594, 1146.4])
8+
x.add_row(["Darwin", 112, 120900, 1714.7])
9+
x.add_row(["Hobart", 1357, 205556, 619.5])
10+
x.add_row(["Sydney", 2058, 4336374, 1214.8])
11+
x.add_row(["Melbourne", 1566, 3806092, 646.9])
12+
x.add_row(["Perth", 5386, 1554769, 869.4])
13+
14+
15+
print(
16+
"-----------------------------------------set_style-----------------------------------------------\n"
17+
)
18+
x.set_style(prettytable.MSWORD_FRIENDLY)
19+
print(x)
20+
21+
22+
# 是否显示边框,默认为True
23+
x.border = True
24+
# 横边框
25+
x.horizontal_char = "^"
26+
# 竖边框
27+
x.vertical_char = ">"
28+
# 边框连接符
29+
x.junction_char = "~"
30+
31+
print(x)
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
prettytable==3.8.0

acrobatics/prettytable/test.csv

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
date,Belgium,China,France,Germany,Iran,Italy,Netherlands,Spain
2+
2020-04-03,1143,3326,6520,1275,3294,14681,1490,11198
3+
2020-04-04,1283,3330,7574,1444,3452,15362,1656,11947
4+
2020-04-05,1447,3333,8093,1584,3603,15887,1771,12641
5+
2020-04-06,1632,3335,8926,1810,3739,16523,1874,13341
6+
2020-04-07,2035,3335,10343,2016,3872,17127,2108,14045
7+
2020-04-08,2240,3337,10887,2349,3993,17669,2255,14792
8+
2020-04-09,2523,3339,12228,2607,4110,18279,2403,15447
9+
2020-04-10,3019,3340,13215,2767,4232,18849,2520,16081
10+
2020-04-11,3346,3343,13851,2894,4357,19468,2653,16606
11+
2020-04-12,3600,3343,14412,3022,4474,19899,2747,17209

acrobatics/pynput/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ control and monitor input devices.
66

77
### Used by pyenv virtualenv pynput
88

9-
工具
109
pyenv virtualenv 3.10.9 pynput
1110
pyenv activate pynput
1211
python -m pip install --upgrade pip

acrobatics/thefuzz/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ thefuzz,Fuzzy String Matching in Python
66

77
### Used by pyenv virtualenv thefuzz
88

9-
工具
109
pyenv virtualenv 3.10.9 thefuzz
1110
pyenv activate thefuzz
1211
python -m pip install --upgrade pip

database/SQLAlchemy/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ SQLAlchemy,database orm framework
66

77
### Used by pyenv virtualenv plugin
88

9-
工具
109
pyenv virtualenv 3.10.9 SQLAlchemy
1110
pyenv activate SQLAlchemy
1211
python -m pip install --upgrade pip

database/redis/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ not say more
66

77
### Used by pyenv virtualenv plugin
88

9-
工具
109
pyenv virtualenv 3.10.9 redis
1110
pyenv activate redis
1211
python -m pip install --upgrade pip

tool/codestyle/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ codestyle,此模块中的工具用于:让团队代码风格一致,符合规
66

77
### Used by pyenv virtualenv plugin
88

9-
工具
109
pyenv virtualenv 3.10.9 codestyle
1110
pyenv activate codestyle
1211
python -m pip install --upgrade pip

tool/loguru/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ loguru,Python logging made (stupidly) simple
66

77
### Used by pyenv virtualenv plugin
88

9-
工具
109
pyenv virtualenv 3.10.9 loguru
1110
pyenv activate loguru
1211
python -m pip install --upgrade pip

tool/mypydantic/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pydantic是使用Python类型注释,进行数据验证和设置管理的工具
66

77
### Used by pyenv virtualenv plugin
88

9-
工具
109
pyenv virtualenv 3.10.9 my-pydantic
1110
pyenv activate my-pydantic
1211
python -m pip install --upgrade pip

tool/rich/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ library for rich text and beautiful formatting in the terminal.
66

77
### Used by pyenv virtualenv rich
88

9-
工具
109
pyenv virtualenv 3.10.9 rich
1110
pyenv activate rich
1211
python -m pip install --upgrade pip

tool/smalltool_collection/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
### Used by pyenv virtualenv plugin
88

9-
工具
109
pyenv virtualenv 3.10.9 smalltool_collection
1110
pyenv activate smalltool_collection
1211
python -m pip install --upgrade pip

tool/watchdog/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Features such as:
99

1010
### Used by pyenv virtualenv watchdog
1111

12-
工具
1312
pyenv virtualenv 3.10.9 watchdog
1413
pyenv activate watchdog
1514
python -m pip install --upgrade pip

tool/yagmail/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ yagmail,Send email in Python conveniently for mail using yagmail
66

77
### Used by pyenv virtualenv yagmail
88

9-
工具
109
pyenv virtualenv 3.10.9 yagmail
1110
pyenv activate yagmail
1211
python -m pip install --upgrade pip

tool/yaml/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ set 、read yaml
66

77
### Used by pyenv virtualenv plugin
88

9-
工具
109
pyenv virtualenv 3.10.9 my-pyyaml
1110
pyenv activate my-pyyaml
1211
python -m pip install --upgrade pip

util/dateutil/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ library for dateutil text and beautiful formatting in the terminal.
66

77
### Used by pyenv virtualenv dateutil
88

9-
工具
109
pyenv virtualenv 3.10.9 dateutil
1110
pyenv activate dateutil
1211
python -m pip install --upgrade pip
13-
cd tool/dateutil
12+
cd util/dateutil
1413
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
1514

1615
### Related documents

util/shortuuid/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# shortuuid
2+
3+
generator concise, unambiguous and URL-safe UUIDs
4+
5+
## use
6+
7+
### Used by pyenv virtualenv shortuuid
8+
9+
pyenv virtualenv 3.10.9 shortuuid
10+
pyenv activate shortuuid
11+
python -m pip install --upgrade pip
12+
cd util/shortuuid
13+
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
14+
15+
### Related documents
16+
17+
shortuuid-github: https://github.com/skorokithakis/shortuuid
18+
19+
## uninstall
20+
21+
pyenv virtualenv-delete shortuuid

util/shortuuid/hello_shortuuid.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
print(
2+
"---------------------------------base useage---------------------------------------"
3+
)
4+
import uuid
5+
6+
print(uuid.uuid4()) # python build-in module
7+
8+
import shortuuid
9+
10+
print(shortuuid.uuid()) # more short
11+
12+
print(
13+
"------------------------------generation uuid from str-------------------------------"
14+
)
15+
print(shortuuid.uuid(name="<http://example.com>")) # ensure generation everytime equal
16+
17+
print(
18+
"----------------------------Specify uuid length---------------------------------------"
19+
)
20+
print(shortuuid.ShortUUID().random(5))
21+
print(shortuuid.ShortUUID().random(10))
22+
print(shortuuid.ShortUUID().random(20))
23+
24+
25+
print(
26+
"--------------------------Output/Set characters used to generate uuids-------------------------"
27+
)
28+
print(shortuuid.get_alphabet())
29+
shortuuid.set_alphabet("abcdefg")
30+
print(shortuuid.uuid())
31+
32+
print(
33+
"---------------------set_alphabet don't affect ShortUUID generation----------------------"
34+
)
35+
print(shortuuid.ShortUUID().random(20))
36+
print(
37+
shortuuid.ShortUUID(alphabet="bcdefg").random(20)
38+
) # ShortUUID need Manual development alphabet
39+
40+
41+
print(
42+
"------------------------------------serialize existing UUIDs--------------------------------"
43+
)
44+
u = uuid.uuid4()
45+
s = shortuuid.encode(u)
46+
print(u) # cf502b50-f75d-4f36-94a9-6bd04789ca55
47+
print(s) # etUe7amvdJvHQY6Emf2TiL
48+
print(shortuuid.decode(s) == u) # True

util/shortuuid/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shortuuid==1.0.11

0 commit comments

Comments
 (0)