语法错误:扫描字符串文字时 EOL -Python
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21089353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SyntaxError: EOL while scanning string literal -Python
提问by user2887592
I am getting SyntaxError:EOL while scanning string literal in this part.
SyntaxError:在这部分扫描字符串文字时,我收到了EOL。
system.cpu.workload = LiveProcess(cmd = 'hello', executable ='hello')
Any help would be apreciated.
任何帮助将不胜感激。
Thank you in advantage!
谢谢你的优势!
回答by Ashwini Chaudhary
Problem is you're using different types of quotes around hello(cmd = 'hello'). One on the left is ASCII single quote and other one is RIGHT SINGLE QUOTATION MARK.
问题是您在hello( cmd = 'hello')周围使用了不同类型的引号。左边一个是 ASCII 单引号,另一个是RIGHT SINGLE QUOTATION MARK.
>>> 'hello'
File "<ipython-input-56-3231cc2cf7bf>", line 1
'hello'
^
SyntaxError: EOL while scanning string literal
>>> 'hello'
'hello'
'is actually a unicode character:
'实际上是一个unicode 字符:
>>> "'".decode('utf-8')
u'\u2019'
回答by Filip Malczak
Right quote surrounding "hello" is wrong - it is backquote, instead of plain one.
围绕“你好”的正确引用是错误的——它是反引号,而不是简单的引用。
回答by Alfe
Looks like you've got a wrong single quote in your code. There are three kinds of quotes in Python:
看起来您的代码中有一个错误的单引号。Python中有三种引号:
" double quote
' single quote
` backtick
Double quotes and single quotes are used interchangeably; use the one kind if the value contains the other to avoid ugly escape sequences using backslashes.
双引号和单引号可以互换使用;如果值包含另一种,则使用一种以避免使用反斜杠的丑陋转义序列。
Backticks, however, are more like an operator and convert the value enclosed by them into its "string representation".
然而,反引号更像是一个运算符,并将它们包含的值转换为其“字符串表示”。
It looks to me as if you mixed single quotes and a backtick in your code.
在我看来,好像您在代码中混合了单引号和反引号。
回答by Bug
You can't create a multiline string with '...'. You have to use ''' ... '''or """ ... """.
您不能使用'...'创建多行字符串。您必须使用''' ... '''或""" ... """。

