如何在 bash 中自动完成我的 python 函数?
How to autocomplete my python functions in bash?
我正在 HPC-Linux-集群上工作,需要使用 python 函数和脚本进行大量 Post 数据处理。
我当前的工作流程如下所示:
- cd 到我的数据所在的文件夹。本来的pythonfunction/script也保存在这个文件夹
- 做:
python myfunction arg1 arg2
- 审核结果
因为这不允许我将我的 python 函数存储在一个位置,所以有时在调试时会很烦人。
所以我想知道是否可以将我的函数存储在一个位置并在 python 命令后自动完成它们而不声明它们的整个路径?
理想情况下它应该是这样的:
python myfunction arg1 arg2
而不是
python path-to-function/myfunction arg1 arg2
我已经设法通过 $PYTHONPATH 在 python 交互中这样做,然后导入我的函数,但坦率地说,我不喜欢这个解决方案,因为它只需要多输入几行.
我还设置了一个全局变量以按以下方式进行:python $MYFUNCTIONS_PATH/myfunction arg1 arg2
但是自动完成不起作用,而且它也是额外的输入。
这是我第一次post来这里,我希望这个问题很好理解。
我不确定,但我这样做是为了在 HPC 上链接进程:
ls your/paths/of/interests/*/ > list.dat
然后:
#You process each of the element in your list
cat list.dat | while read -r line; do
#You cd to it
cd ${line}/gromacs/
#You use EOF to pass arguments
gmx distance -f step7_all.xtc -oall DIST_D103_K81_${line}.xvg -n index.ndx -
select 'cog of group "r_103_&_OD1_OD2" plus cog of group "r_81_&_NZ"' <<EOF
20
EOF
#You take your stuff away and cd back
cp DIST*xvg ../../
cd ../../
我找到了适合我的问题的解决方案,而且更舒服。
在您的 python 脚本(Shebang)的第一行添加 python 作为执行者及其路径:
#!/usr/bin/python
如果您不确定您的 pyhton 路径,请执行:ẁhich python
将您想要的所有 python 脚本存储在合适的位置并将此位置添加到您的路径(例如,在您的 .bashrc 中):
PATH=$PATH:/path/to/your/python/scripts
使您在此位置的所有脚本可执行:
chmod +x
在重新登录或采购后 your.bashrc 您现在应该可以 运行 使用自动完成从任何地方获取脚本,您甚至不必在之前输入“python”脚本名称:
yourscript.py arg1 arg2
另见 。
我正在 HPC-Linux-集群上工作,需要使用 python 函数和脚本进行大量 Post 数据处理。 我当前的工作流程如下所示:
- cd 到我的数据所在的文件夹。本来的pythonfunction/script也保存在这个文件夹
- 做:
python myfunction arg1 arg2
- 审核结果
因为这不允许我将我的 python 函数存储在一个位置,所以有时在调试时会很烦人。
所以我想知道是否可以将我的函数存储在一个位置并在 python 命令后自动完成它们而不声明它们的整个路径?
理想情况下它应该是这样的:
python myfunction arg1 arg2
而不是
python path-to-function/myfunction arg1 arg2
我已经设法通过 $PYTHONPATH 在 python 交互中这样做,然后导入我的函数,但坦率地说,我不喜欢这个解决方案,因为它只需要多输入几行.
我还设置了一个全局变量以按以下方式进行:python $MYFUNCTIONS_PATH/myfunction arg1 arg2
但是自动完成不起作用,而且它也是额外的输入。
这是我第一次post来这里,我希望这个问题很好理解。
我不确定,但我这样做是为了在 HPC 上链接进程:
ls your/paths/of/interests/*/ > list.dat
然后:
#You process each of the element in your list
cat list.dat | while read -r line; do
#You cd to it
cd ${line}/gromacs/
#You use EOF to pass arguments
gmx distance -f step7_all.xtc -oall DIST_D103_K81_${line}.xvg -n index.ndx -
select 'cog of group "r_103_&_OD1_OD2" plus cog of group "r_81_&_NZ"' <<EOF
20
EOF
#You take your stuff away and cd back
cp DIST*xvg ../../
cd ../../
我找到了适合我的问题的解决方案,而且更舒服。
在您的 python 脚本(Shebang)的第一行添加 python 作为执行者及其路径:
#!/usr/bin/python
如果您不确定您的 pyhton 路径,请执行:
ẁhich python
将您想要的所有 python 脚本存储在合适的位置并将此位置添加到您的路径(例如,在您的 .bashrc 中):
PATH=$PATH:/path/to/your/python/scripts
使您在此位置的所有脚本可执行:
chmod +x
在重新登录或采购后 your.bashrc 您现在应该可以 运行 使用自动完成从任何地方获取脚本,您甚至不必在之前输入“python”脚本名称:
yourscript.py arg1 arg2
另见