gpt4 book ai didi

Python --command 命令行选项

转载 作者:太空宇宙 更新时间:2023-11-04 08:10:06 26 4
gpt4 key购买 nike

我正在尝试使用 python -c 命令行选项,但似乎无法使其工作。什么是正确的使用方法?有时存储整个命令和一行并为其创建别名然后进入交互模式真的很有用。

下面没有输出

-bash-3.2$ python -c "
import hashlib
hashlib.md5('test').hexdigest()"

当然还有后续作品

-bash-3.2$ python
>>> import hashlib
>>> hashlib.md5('test').hexdigest()
'098f6bcd4621d373cade4e832627b4f6'
>>>

最佳答案

如果在非交互模式下,您必须打印您想要查看的内容。

python -c "import hashlib
print hashlib.md5('test').hexdigest()"

交互模式总是打印返回值,但这只是CLI的一个噱头

关于Python --command 命令行选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24023643/

26 4 0
文章推荐: python - 1.6 版的 Django 教程
文章推荐: javascript - 在进行事件处理练习时,为什么我不需要使用 componentDidMount() 方法?
文章推荐: 单行文本的 HTML 标记 vs

vs