Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Invalid character in identifier

I have some code that includes:

def analysis_result (results):
 keys = analysis.keys ()
 values ​​= list(analysis.values ​​())
 values.sort (reverse = True )
 # More code...

But I get an error from the values ​​= list(analysis.values ​​()) line that says SyntaxError: invalid character in identifier. Why? What is wrong with the code, and how do I fix it?

Note carefully that retyping the code as it appears does not cause a SyntaxError, but copying and pasting it does.


The error here is due to non-printing text that cannot be seen in the code example. Do not close the question as not reproducible, and take special care when editing. At some prior point in the question's history, it was edited to try to "show" the invalid character by using a backslash escape sequence. This does not work; we can only see this by treating the code as a string and asking Python for a string representation. While it would also be incorrect to type code that uses backslash escape sequences, the error message would be different.

Answer*

Draft saved
Draft discarded
Cancel
1
  • I also got this error as a result of copy/pasting code from a gmail draft. Commented Oct 14, 2019 at 20:34

lang-py

AltStyle によって変換されたページ (->オリジナル) /