Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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 3.x 多次检查但仍存在语法错误:扫描字符串文字时下线_Python 3.x - Fatal编程技术网

Python 3.x 多次检查但仍存在语法错误:扫描字符串文字时下线

Python 3.x 多次检查但仍存在语法错误:扫描字符串文字时下线,python-3.x,Python 3.x,我多次检查该字符串以确保(“.”)已就位,但消息 File "<ipython-input-13-ef09f7b4583b>", line 48 plt.savefig("C:\scratch\\data\"+str(angle).zfill(3)+".") SyntaxError: EOL while scanning string literal Python字符串不能以\结尾,因为这将逃避关闭的“(或”) 您有几个选择: 以固定方式使用双反斜杠: plt.savefig(

我多次检查该字符串以确保(“.”)已就位,但消息

File "<ipython-input-13-ef09f7b4583b>", line 48 plt.savefig("C:\scratch\\data\"+str(angle).zfill(3)+".")

SyntaxError: EOL while scanning string literal

Python字符串不能以
\
结尾,因为这将逃避关闭的
(或

您有几个选择:

  • 以固定方式使用双反斜杠:

    plt.savefig("C:\\scratch\\data\\" + str(angle).zfill(3) + ".png")
    
  • 使用
    .format
    ,最好与原始字符串组合使用,以避免目录名以
    t
    n
    或任何其他字符开头时出现问题,这些字符在前缀为
    \
    时将成为控制序列:

    plt.savefig(r"C:\scratch\data\{}.png".format(str(angle).zfill(3)))
    
plt.savefig(r"C:\scratch\data\{}.png".format(str(angle).zfill(3)))