用户名收集
dukep的Python项目详细描述
杜比
有用的python代码片段的集合
pip install dukepy
配置
confirationmanager(使用json)能够
- 添加新键
- 删除不推荐使用的键(即不在默认值中的键)
- 备份(json)配置文件的旧版本
生成的示例文件-
C:\users\xyz.myconfig\config.json
{"newkey1":"newvalue1","newkeygroup1":{"newkey2":"newvalue2"},"newkey3":["newvalue4","newvalue4"],"newkey5":"newvalue5"}
用法示例-
importosfromdukepy.configimportConfigconfig_dir=os.path.join(os.path.expanduser("~"),".myconfig")config_file=os.path.join(config_dir,"config.json")Config(path=config_file,defaults={"newkey1":"newvalue1","newkeygroup1":{"newkey2":"newvalue2"},"newkey3":["newvalue4","newvalue4"]})Config()["newkey5"]="newvalue5"Config().commit()
收敛
求有限序列的极值,假设序列是连续的。 在序列中提供至少两个已知的数字, 并提出了一种检验算法预测数有效性的方法。
用法示例-
defcheck_validity(val):ifval>-30andval<101:returnTrueelse:returnFalselow,high=Converge(-28,50,check_validity).run()print(low)print(high)
输出-
-29
100
dict_diff
- 找出两个字典之间的递归差异。
- 用另一个字典更新一个字典(每个字典都是可选的)-
- 从另一个添加键
- 取下不属于另一个钥匙的钥匙
- 从另一个键更新值
用法示例-
dictionary_1={"abc":"value_abc","prs":"value_prs"}dictionary_2={"abc":"value_abc","xyz":"value_xyz"}dict_diff(dictionary_1,dictionary_2)print(dictionary_1)print(dictionary_2)dict_diff(dictionary_1,dictionary_2,udpate_added_keys=True)print(dictionary_1)print(dictionary_2)
输出-
:
- prs : value_prs
:
+ xyz : value_xyz
{'abc': 'value_abc', 'prs': 'value_prs'}
{'abc': 'value_abc', 'xyz': 'value_xyz'}
:
- prs : value_prs
:
+ xyz : value_xyz
{'abc': 'value_abc', 'prs': 'value_prs', 'xyz': 'value_xyz'}
{'abc': 'value_abc', 'xyz': 'value_xyz'}
记录器
邮箱
安全指令
单重态
taces
打印异常的来源,而不仅仅是异常字符串。 用法示例-
mydict=dict()try:print(mydict["sdf"])exceptExceptionase:print_exception_traces(e)
输出-
Traceback (most recent call last):
File "C:/Dev/libpython/src/dukepy/traces.py", line 16, in <module>
print(mydict["sdf"])
KeyError: 'sdf'