Skip to main content
 首页 » 编程设计

android之从外部 SD 卡运行 Py4A 脚本

2025年05月04日22del

我需要从外部 SD 卡运行 Python 脚本,它在目标设备中安装为 /mnt/sdcard/_ExternalSD。

通过在标准 SL4A 脚本目录中准备“代理”脚本 ExtSDRun.py,我已经成功地以快速且肮脏的方式实现了这一点,如果我的目标设备是 /mnt/sdcard/sl4a/scripts

import android 
droid = android.Android() 
import os 
import sys 
# Add directory with the scripts to the Python path 
sys.path.append("/mnt/sdcard/_ExternalSD/scripts") 
# Start the script located in the external SD card 
# in the script_to_run.py file 
import script_to_run 
# You can also do: 
# from script_to_run import * 

有没有更好更优雅的方式来实现这个目标?

请您参考如下方法:

我很确定您可以从外部 SD 卡运行脚本。尝试 this .这是一个简单的 Python 函数,可以启动任何脚本 SL4A 已为其安装了解释器,给定脚本的任意路径。我没有外部卡来对其进行测试,但没有理由失败。