如何使用 zsh 函数运行任何 python 脚本

问题描述 投票:0回答:1

我正在尝试创建一个别名/函数,让我无需输入即可运行 python 脚本

python3 whatever.py
别名应将
py whatever
变为
python3 whatever.py

这是我迄今为止尝试过的:

py() {
  python3 "$1.py"
}

我尝试在 py() 前面添加函数,删除引号,并且只在 $1 左右添加引号。但运气不好。 当我尝试

py test
(确实存在)时:

/Library/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python: can't open file '/Users/my_username/Code/test': [Errno 2] No such file or directory

有什么技巧/更好的方法吗? 顺便说一句,我正在使用 zsh

zsh zshrc zsh-alias
1个回答
0
投票

所以事实证明,调用函数

py()
不起作用,尽管
whence -vf py
表示
py not found

无论如何,我将其更改为 p(),并且

p test
正确运行了 test.py。

© www.soinside.com 2019 - 2024. All rights reserved.