Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCody Stephenson
8,361 PointsSolution to the "SyntaxError: Invalid Character in Identifier" you might get from the color_mapper code. [Feedback]
While trying to use the color_mapper
code I got a "SyntaxError: Invalid Character in Identifier" error. I'm doing this course in a Jupyter Notebook so I'm not sure this will happen in other IDEs. When you copy and paste the code you get
color_mapper = CategoricalColorMapper(factors=[‘Asia’, ‘Africa’, ‘Antarctica’, ‘Australia’, ‘Central America’, ‘Europe’, ‘North America’, “Oceania’, ‘South America’], palette=[‘#00FF00’, ‘#FFD343’, ‘darkgray’, ‘brown’, ‘cyan’, ‘crimson’, ‘red’, ‘#0000FF’, ‘purple’])
and you can see that syntax coloring goes wonky part way through, which along with the error told me there is a character being misinterpreted. I checked for non-printable characters with repr()
and to see if any of the color codes need to be escaped out for some reason. Eventually, I noticed that the issue seems to be curly ‘’
vs straight ''
quotes.
I threw it in Sublime to find and replace all curlys with straights and got
color_mapper = CategoricalColorMapper(factors=['Asia', 'Africa', 'Antarctica', 'Australia', 'Central America', 'Europe', 'North America', 'Oceania', 'South America'], palette=['#00FF00', '#FFD343', 'darkgray', 'brown', 'cyan', 'crimson', 'red', '#0000FF', 'purple'])
Which makes the syntax coloring happy and resolves the error.
1 Answer
Ken Alger
Treehouse TeacherNice catch Cody Stephenson. Sometimes the various quotation marks definitely matter and the "smart quotes" get render in wonky ways.
Pleased to hear that you worked it out.
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsThanks! Flagging as feedback.
Developers: Please update the teachers notes with corrected string quotation marks.