[英]Python - EOL while scanning string literal of an Import statement
I am trying to test an s3 package using the command line, saying py -c 'import s3'
and I receive an error for EOL end of string literal. 我正在尝试使用命令行测试s3软件包,并说
py -c 'import s3'
并且我收到字符串文字的EOL结尾错误。 Even though most of the other questions about EOL deal with not closing quotes or escaping characters, mine is a simple import statement. 即使有关EOL的大多数其他问题都涉及不使用右引号或转义字符,但mine是一个简单的import语句。 What could be wrong with the way I formatted it?
我的格式化方式可能有什么问题?
there's nothing wrong with the source code (as far as i know), it's simply because you are using single quotes in the command line, which are not interpreted as grouping with spaces (on windows, which i can tell you are because you are using py
). 源代码没有任何问题(据我所知),这仅仅是因为您在命令行中使用了单引号,而不将其解释为以空格分组(在Windows上,我可以告诉您的是,因为您正在使用
py
)。 just use double quotes: py -c "import s3"
. 只需使用双引号即可:
py -c "import s3"
。 since the string is not being passed as a full argument, the python interpreter is just receiving 'import`, which is, as you probably know, not valid syntax :). 由于未将字符串作为完整参数传递,因此python解释器仅接收“ import”,这可能是无效的语法:)。 if you want a simple program to show you why this how this happens in windows, i have this:
如果您想要一个简单的程序来显示为什么这在Windows中是如何发生的,我有这个:
import sys
print(sys.argv)
on windows: 在Windows上:
C:\Users\Michael\Desktop>py argv.py 'a sentence'
['argv.py', "'a", "sentence'"]
and on linux: 在Linux上:
michael@Michael:/mnt/c/Users/Michael/Desktop$ python3 argv.py 'a sentence'
['argv.py', 'a sentence']
so, on windows, just use double quotes instead of single quotes, when passing command line arguments with spaces, because they will still be split on the spaces. 因此,在Windows上,在传递带有空格的命令行参数时,只需使用双引号而不是单引号,因为它们仍将在空格处分割。 on linux, it doesnt matter.
在linux上,没关系。 once again, the solution to your problem is just to type:
再一次,您的问题的解决方案是键入:
py -c "import s3"
instead of: py -c 'import s3'
py -c "import s3"
代替: py -c 'import s3'
have a good day! 祝你有美好的一天!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.