1 回答

TA貢獻1856條經驗 獲得超11個贊
為同一目錄下的2個文件生成
創建一個以內容命名的 python 文件create_diagrams.py:
from plantuml import PlantUML
from os.path import abspath
# create a server object to call for your computations
server = PlantUML(url='http://www.plantuml.com/plantuml/img/',
basic_auth={},
form_auth={}, http_opts={}, request_opts={})
# Send and compile your diagram files to/with the PlantUML server
server.processes_file(abspath('./example_flow.txt'))
server.processes_file(abspath('./Graphviz_example.txt'))
并運行它,例如在帶有 python 3.6 的 anaconda 中使用命令:python create_diagrams.py。
為目錄中的所有文件生成
還可以為.txt目錄中的所有文件生成圖表Diagrams:
from plantuml import PlantUML
import os
from os.path import abspath
server = PlantUML(url='http://www.plantuml.com/plantuml/img/',
basic_auth={},
form_auth={}, http_opts={}, request_opts={})
# create subfolder name
diagram_dir = "./Diagrams"
# loop through all .txt files in the subfolder
for file in os.listdir(diagram_dir):
filename = os.fsdecode(file)
if filename.endswith(".txt"):
# Call the PlantUML server on the .txt file
server.processes_file(abspath(f'./Diagrams/{filename}'))
筆記
此實現需要有效的互聯網連接,因為您要求 PlantUML 服務器為您生成圖形。要在本地編譯,您還可以下載.jarPlantUML 軟件的文件并從 python 調用它來進行計算。這篇文章的問題中給出了一個更詳細的例子。
添加回答
舉報