Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python plotly.io.write_image()通过添加/&引用;这使得这条路毫无用处_Python_Plotly - Fatal编程技术网

Python plotly.io.write_image()通过添加/&引用;这使得这条路毫无用处

Python plotly.io.write_image()通过添加/&引用;这使得这条路毫无用处,python,plotly,Python,Plotly,我想将一些plotly graph对象图形保存为svg文件。我的代码如下所示: import plotly.io as pio pio.write_image(figOIA, "S:\FC\FCD\06_Datenbanken\FCD Dashboard\Plots Budget-Ausschöpfung/asdf.svg")) 但我有一个错误是这样说的: > OSError: [Errno 22] Invalid argument: 'S:\\FC\\FCD

我想将一些plotly graph对象图形保存为svg文件。我的代码如下所示:

import plotly.io as pio
pio.write_image(figOIA, "S:\FC\FCD\06_Datenbanken\FCD Dashboard\Plots Budget-Ausschöpfung/asdf.svg"))
但我有一个错误是这样说的:

>     OSError: [Errno 22] Invalid argument: 'S:\\FC\\FCD\x06_Datenbanken\\FCD Dashboard\\Plots
> Budget-Ausschöpfung/asdf.svg'
显然,write_image()函数更改了我的目录。为什么要在“06_Datenbanken”前面加“/”和“x”?这太令人沮丧了,因为我不知道这是怎么发生的,非常感谢您的帮助,谢谢

从答案中我现在知道错误是什么了。但当我现在尝试此代码时:

 raw_string = r"S:\FC\FCD\06_Datenbanken\FCD Dashboard\Plot Budget-Ausschöpfung" + r"/" + r"{}".format(today.year) + r"_" + r"{}".format(today.month) + r"_" + r"{}".format(Ressort_value) + r"_Budget-Ausschöpfung.svg"
     pio.write_image(figOIA, raw_string )
我仍然得到这个错误:

>     FileNotFoundError: [Errno 2] No such file or directory: 'S:\\FC\\FCD\\06_Datenbanken\\FCD Dashboard\\Plot
> Budget-Ausschöpfung/2020_7_Alle_Budget-Ausschöpfung.svg'

因此,双反斜杠仍然存在。。这次怎么了?

反斜杠字符
\
用作Python字符串中的特殊转义字符。为了阻止这种特殊处理,您必须将它们加倍为
\\
,或者使用原始字符串

pio.write_image(figOIA, "S:\\FC\\FCD\\06_Datenbanken\\FCD Dashboard\\Plots Budget-Ausschöpfung/asdf.svg"))


不幸的是,Windows使用与大多数语言用于特殊字符串转义序列的路径分隔符相同的字符。当然,出于同样的原因,反斜杠\\是一个很少使用的字符。您尝试过最新版本吗?显然,他们增加了一个更好的支持写静态图像检查谢谢你的帮助!但不幸的是,即使使用原始字符串,我的代码仍然有一些错误。我现在编辑了我的问题。@thyhmoo当你看字符串时,反斜杠也会加倍,但是如果你使用
print
你就看不到了。我想说这个文件确实不存在,可能是因为重音字符没有被正确处理。
pio.write_image(figOIA, r"S:\FC\FCD\06_Datenbanken\FCD Dashboard\Plots Budget-Ausschöpfung/asdf.svg"))