[英]How to modify the contents of an .SVG file with Python?
我有一個帶有示例內容的.svg 文件: <svg style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.001" /></svg>
我現在想使用 Python 直接編輯 .svg 文件並將style="fill:#000000;
更改為我想要的顏色並保存它。但是我不確定如何 Z34D1F91FB2E514B8576ZFAB1A但沒有人做我需要的。
試試這個: https://pythonexamples.org/python-replace-string-in-file/
#read input file
fin = open("data.svg", "rt")
#read file contents to string
data = fin.read()
#replace all occurrences of the required string
data = data.replace('style="fill:#000000;', 'style="fill:#FF0000;')
#close the input file
fin.close()
#open the input file in write mode
fin = open("data.svg", "wt")
#overrite the input file with the resulting data
fin.write(data)
#close the file
fin.close()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.