我有上述错误s1="一些很长的字符串............"
有人知道我哪里做错了吗?
我有上述错误s1="一些很长的字符串............"
有人知道我哪里做错了吗?
当前回答
在这种情况下,三单报价或三双报价都可以! 例如:
"""Parameters:
...Type something.....
.....finishing statement"""
OR
'''Parameters:
...Type something.....
.....finishing statement'''
其他回答
(假设你没有/不想在你的字符串中换行…)
这个字符串到底有多长?
我怀疑从文件或命令行读取一行的长度是有限制的,因为行尾被截断,解析器会看到类似s1="一些非常长的字符串..........(没有结尾),从而抛出解析错误?
你可以通过在源代码中转义换行符将长行拆分为多行,如下所示:
s1="some very long string.....\
...\
...."
你没有在一行的末尾加上“”。
如果你想这样做,使用""":
""" a very long string ......
....that can span multiple lines
"""
我遇到了这个问题——我最终发现原因是我在字符串中包含了\字符。如果你有任何这些,“转义”他们与\\,它应该工作正常。
在我使用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")
它工作…
大卫
变量(s1)跨越多行。为了做到这一点(即你想要你的字符串跨越多行),你必须使用三引号(""")。
s1="""some very long
string............"""