简体   繁体   中英

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. Even though most of the other questions about EOL deal with not closing quotes or escaping characters, mine is a simple import statement. 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 ). just use double quotes: 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 :). if you want a simple program to show you why this how this happens in windows, i have this:

import sys
print(sys.argv)

on windows:

C:\Users\Michael\Desktop>py argv.py 'a sentence'
['argv.py', "'a", "sentence'"]

and on 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. on linux, it doesnt matter. once again, the solution to your problem is just to type:
py -c "import s3" instead of: py -c 'import s3'
have a good day!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM