Python Forum

Full Version: Something wrong with the quotation mark in dictionary definition
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying out an Eliza chatbot I found online. The code starts with:
import re
import random
reflections = {
    “am”: “are”,
    “was”: “were”,
    “i”: “you”,
    “i’d”: “you would”,
    “i’ve”: “you have”,
    “i’ll”: “you will”,
    “my”: “your”,
    “are”: “am”,
    “you’ve”: “I have”,
    “you’ll”: “I will”,
    “your”: “my”,
    “yours”: “mine”,
    “you”: “me”,
    “me”: “you”
}
Right off the top, Spyder is giving me:
Material\Miscellaneous\Python\untitled1.py", line 11
    “am”: “are”,
       ^
SyntaxError: invalid character in identifier
What's invalid here? Thanks!
You use these chars

https://www.compart.com/en/unicode/U+201C
https://www.compart.com/en/unicode/U+201D

and it should be
https://www.compart.com/en/unicode/U+0022
or apostrophe
https://www.compart.com/en/unicode/U+0027

reflections = {
    "am": "are",
    "was": "were",
    "i": "you",
    "i’d": "you would",
    "i’ve": "you have",
    "i’ll": "you will",
    "my": "your",
    "are": "am",
    "you’ve": "I have",
    "you’ll": "I will",
    "your": "my",
    "yours": "mine",
    "you": "me",
    "me": "you"
}
I guess you copy the code from some site that uses fancy/incorrect representation.