[英]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.