Reputation: 13940
SYNTAX ERROR (please copy/paste to see)
x = {
"0":"G",
"1":"H"
}
Tested on line interpreter:
>>> x = {
... "0":"G"
File "<stdin>", line 2
"0":"G"
^
SyntaxError: invalid syntax
But this other (seems the same!) is fine, (please copy/paste to see)
x = {
"0":"G",
"1":"H"
}
The real-life dictionary is longer and complex, but it is from a PDF and I copy/paste to editor (or direct to terminal same result). Perhaps (after comment that confirm) it is a ASCII convertion problem and I need to clean... So que question is "how to sanitize copy/paste source-code that seeems perfect?"
Tested with both:
python --version
= Python 2.7.17python3 --version
= Python 3.6.9Upvotes: 0
Views: 63
Reputation: 71
I just tried in 3.6 console - it highlights some odd spacing around first colon and clearly says "SyntaxError: invalid character in identifier". See screenshot
As @mpez0 already commented - when you copy from PDF (Word etc), a bunch of extra characters tag along.
Upvotes: 1
Reputation: 358
I can't comment, so I will write this as an answer.
Depending on the text editor you are using, I suggest looking for a package that can do this. Here's one for Sublime Text.
There are also some online tools to copy/paste your source and check or sanitize it. Examples:
Upvotes: 1