![](/img/trans.png)
[英]Cross-platform way to check admin rights in a Python script under Windows?
[英]How to run a Python script from another Python script in the cross-platform way?
這是問題所在...
我正在為Blender寫一個非常小的插件,我有10個python腳本,它們通過使用命令行來解析不同的文件格式,並且我有一個Main Python腳本來使用適當的命令運行所有其他腳本...
例如,“ Main.py”包括:
txt2cfg.py -inFile -outFile ...
ma2lxo.py -inFile -outFile ...
Blender已經包含Python,因此我可以從Blender運行“ Main.py”,但是我需要它同時與PC和MAC一起使用,並且不需要Python安裝,因此我不能使用:
因為他們需要安裝Python才能運行* .py文件。
對不起語言
謝謝
如果您確實需要在新進程中執行python腳本,並且不知道所需的解釋器在哪里,請使用sys模塊來提供幫助。
import sys
import subprocess
subprocess.Popen((sys.executable, "script.py"))
盡管(如果需要的話)動態導入模塊,然后在另一個腳本中運行其main方法可能是一個更好的主意。
例如,“ Main.py”包括:
txt2cfg.py -inFile -outFile ... ma2lxo.py -inFile -outFile ...
兩件事情。
每個其他腳本都需要main()函數和“ main-import開關”。 有關該外觀的提示,請參見http://docs.python.org/tutorial/modules.html#executing-modules-as-scripts 。
導入並執行其他腳本。
import txt2cfg import ma2lxo txt2cfg.main( inFile, outFile ) ma2lxo.main( inFile, outFile )
這是做事的最簡單方法。
兩種選擇:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.