27 Star 5 Fork 51

qpy-doc-center / teedoc_with_qpydoc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
example.md 848 Bytes
一键复制 编辑 原始数据 按行查看 历史

example - 执行python脚本

提供方法让用户可以在命令行或者代码中执行python脚本。

example.exec

example.exec(filePath)

执行指定的python脚本文件。

参数描述

  • filePath,string类型, 要执行python脚本文件的绝对路径

示例

# 假设有文件test.py,内容如下

def myprint():
    count = 10
    while count > 0:
        count -= 1
        print('##### test #####')

myprint()

#将test.py文件上传到模块中,进入命令行执行如下代码
>>> uos.listdir('/usr/')
['apn_cfg.json', 'test.py']
>>> import example
>>> example.exec('/usr/test.py')
# 执行结果如下

##### test #####
##### test #####
##### test #####
##### test #####
##### test #####
##### test #####
##### test #####
##### test #####
##### test #####
##### test #####
1
https://gitee.com/qpy-doc-center/teedoc_with_qpydoc.git
git@gitee.com:qpy-doc-center/teedoc_with_qpydoc.git
qpy-doc-center
teedoc_with_qpydoc
teedoc_with_qpydoc
main

搜索帮助