开发者

Path for running Python files

开发者 https://www.devze.com 2023-04-03 19:52 出处:网络
I have a directory which I would like to be the default for Python scripts so when a user is running python foo.py arg1 arg2 and foo.p开发者_高级运维y is not in the current directory, it should execut

I have a directory which I would like to be the default for Python scripts so when a user is running python foo.py arg1 arg2 and foo.p开发者_高级运维y is not in the current directory, it should execute python /defaultdir/foo.py arg1 arg2. Neither $PATH nor $PYTHONPATH is good for that: the first would only work with the command foo.py arg1 arg2, which requires a hashbang in the script and execution rights, while the second only works for import˙commands from an already running script. I suppose I could replace the Python binary with a wrapper, but I would prefer a cleaner solution if there was one.


Use python -m:

python -mfoo arg1 arg2
0

精彩评论

暂无评论...
验证码 换一张
取 消