Python Forum
Something wrong with the quotation mark in dictionary definition
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Something wrong with the quotation mark in dictionary definition
#1
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!
Reply
#2
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  class definition and problem with a method HerrAyas 2 211 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  mutable argument in function definition akbarza 1 464 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  error occuring in definition a class akbarza 3 684 Nov-26-2023, 09:28 AM
Last Post: Yoriz
  determine parameter type in definition function akbarza 1 570 Aug-24-2023, 01:46 PM
Last Post: deanhystad
  [split] Explain the python code in this definition Led_Zeppelin 1 734 Jan-13-2023, 10:20 PM
Last Post: deanhystad
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,514 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Explain the python code in this definition Led_Zeppelin 1 1,078 Oct-27-2022, 04:04 AM
Last Post: deanhystad
  meaning of -> syntax in function definition DrakeSoft 5 1,936 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Mark outlook emails as read using Python! shane88 2 6,531 Feb-24-2022, 11:19 PM
Last Post: Pedroski55
  Doctesting a function which prints a students name along with the maximum mark scored sean1 5 2,247 Feb-01-2022, 12:20 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020