Python
2023-03-04
今天了解到这个库,为一些演示工作的方便而开发。用 Python 来配置界面,主要是输入、输出,然后将输入的参数传入处理方法,将返回值显示在输出。
PS:安装的时候可以看到,这个库有 14M,而且其他的依赖不少。
这只是一个简单的示例:
import gradio as gr
def greet(name):
return "Hello " + name + "!"
# demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo = gr.Interface(
fn=greet,
inputs=gr.Textbox(lines=2, placeholder="Name Here..."),
outputs="text",
)
demo.launch()
python gradioTest.py
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.

以后需要用到这个的时候再来研究研究。
Python 时间 Cygwin
2023-02-24
Cygwin 下执行一个 Python 脚本,其中 datetime.now()
获取到的时间居然是 UTF 时间。
执行 date 命令也是如此。
执行 tzselect,三次分别选 Asia,China,Beijing Time,然后就好了。
命令中有提示:如果要永久有效,需要在 ~/.profile 中加入 TZ='Asia/Shanghai'
。
关键是,TZ 其实有配置:
export | grep TZ
declare -x TZ="Asia/Shanghai"
Python
2022-12-19
Python 测试 pytest
2022-07-12
- 全局
setup_module(module)
/ teardown_module(module)
引入包的时候执行
setup_function(function)
/ teardown_function(function)
- 模块级别
setup()
/ teardown()
测试模块载入的时候执行
- 类级别
setup_class(cls)
/ teardown_class(cls)
setup_method(self, method)
/ teardown_method(self, method)
setup(self)
/ teardown(self)
nose 语法,会被上面两个方法覆盖
Supported nose Idioms
setup()
and teardown()
at module/class/method level: any function or method called setup
will be called during the setup phase for each test, same for teardown
.
SkipTest
exceptions and markers
- setup/teardown decorators
__test__
attribute on modules/classes/functions
- general usage of nose utilities
Pipenv Python
2022-05-16
pipenv requirements > requirements.txt && pipenv requirements --dev-only > requirements-dev.txt
开发者 Python
2022-04-19
Python pip pipx
2022-01-13
pipx 和 pip 一样,也是来自 PyPA 的项目。
PS: PyPA 的知名项目包括 pipenv, pip, pipx, virtualenv, flit, twine。
pipx 的作用是将包安装在虚拟环境中(利用标准库中的 venv)。用来安装一些 Python 写的工具就很好,不需要关心这些工具的代码时。
Python Poetry
2022-01-12
我研究了半天之后感觉无法掌握 poetry,决定放弃,还是用我的 Pipenv。

Poetry 是一个 Python 虚拟环境管理器。
Python 测试 pytest
2022-01-10
给 tmuxp 提了一个 Issue, 作者 @tony (Tony 老师?😜) 让我选择是自己写测试,还是他来写。
我表达我对 pytest 不熟之后,他给我一点建议:
所以我先学习学习,然后抽空把 test 自己写了。
Python GIL
2021-10-22
开源中国上看到有人通过一些实验验证来视图说服 Python 核心团队移除 GIL,根据他的数据,移除 GIL 可以大幅提升多线程性能(19.8 倍)。
Python
2021-10-11
Python 3.10 前几天刚发布。
Python 3.11 据说性能可以提升 2 - 5 倍(2021/05/18, 关于 CPython 的 Shannon Plan),期待!
回顾以下 Python 的版本历史。
安全 加密 sm3 Python
2021-10-03
sm3
是我国设计的一种哈希算法,根据维基百科信息,大致相当于 sha256
。
Python 哈希函数
2021-10-01
一个不值一提的小问题:
有个地方使用 hash
方法来做哈希计算,将字符串转换成一个数值,但是发现改用 Python 3 之后,这个值每次运行都不一样了。
Python 哈希函数 密码学
2021-10-01
开发时,有时候我们需要将任意字符串映射成一个数字或字符串,这就是哈希。
Python PIL 图像处理
2021-09-30
效果:
