我有上述错误s1="一些很长的字符串............"

有人知道我哪里做错了吗?


当前回答

在访问任何硬盘目录时,我都遇到过同样的问题。 然后我用这种方法解决了它。

 import os
 os.startfile("D:\folder_name\file_name") #running shortcut
 os.startfile("F:") #accessing directory

上图显示了一个错误和已解决的输出。

其他回答

你没有在一行的末尾加上“”。

如果你想这样做,使用""":

""" a very long string ...... 
....that can span multiple lines
"""

在我的例子中,我使用Windows,所以我必须使用双引号而不是单引号。

C:\Users\Dr. Printer>python -mtimeit -s"a = 0"
100000000 loops, best of 3: 0.011 usec per loop

在这种情况下,三单报价或三双报价都可以! 例如:

    """Parameters:
    ...Type something.....
    .....finishing statement"""

OR

    '''Parameters:
    ...Type something.....
    .....finishing statement'''

在我使用Mac OS X的情况下,我有以下声明:

model.export_srcpkg(platform, toolchain, 'mymodel_pkg.zip', 'mymodel.dylib’)

我得到了错误:

  File "<stdin>", line 1
model.export_srcpkg(platform, toolchain, 'mymodel_pkg.zip', 'mymodel.dylib’)
                                                                             ^
SyntaxError: EOL while scanning string literal

当我改为:

model.export_srcpkg(platform, toolchain, "mymodel_pkg.zip", "mymodel.dylib")

它工作…

大卫

你可以试试这个:

s = r'long\annoying\path'