将命令行参数传递给QPython
答
只需编写一个包装脚本来获取参数并使用execfile等函数传递给实际脚本,并将该脚本放入/sdcard/com.hipipal.qpyplus/scripts或/sdcard/com.hipipal.qpyplus/ scripts3(用于qpython3)。
然后,您可以在单击开始按钮时在脚本中看到脚本。
答
我发现了一些运行我从Linux笔记本电脑导入的脚本的方法。
如果我把frets.py
在script3
目录,并在同一目录中创建此脚本:
import sys, os
dir = '/storage/emulated/0/com.hipipal.qpyplus/scripts3/'
os.chdir(dir)
def callfrets(val):
os.system(sys.executable+" frets.py " + val)
while True:
val = input('$:')
if val:
callfrets(val)
else:
break
我可以用我在Linux中使用的相同的命令行输入运行程序,在控制台上获得输出。只需从编辑器或programs
菜单中调用此脚本即可。
我也发现了(得到了一些错误后),我可以用sys.exit(1)
在quiting Python的控制台得到一个可用的Linux命令:
import sys
sys.exit(1)
下降我与/
目录壳。更改目录
cd /storage/emulated/0/Download # or to the scripts3 directory
让我运行原始脚本直接
python frets.py -a ...
这个壳有必要permisions和$PATH
(/data/data/com.hipipal.qpy3/files/bin
)。
(我有问题让我的手机可以正常工作,但更新Qpython3照顾了这一点。)