我无法弄清楚为什么这段代码中存在语法错误

I can't figure out why there is a syntax error in this code

所以我有这个 python 代码,我要在 mac 的终端中 运行 但是当我尝试 运行 将它与 python 在终端中,它在第 27 行给我一个语法错误,如下所示:

          python /Users/ssddeveloper/Desktop/observer.py 
  File "/Users/ssddeveloper/Desktop/observer.py", line 27
    self.data = raw_input(‘Enter Pressure,Temperature,WindDirection:’)
                      ^

我一直在尝试并试图弄清楚为什么首先会出现语法错误,也许这真的很简单,但我只是不知道,但是是的。该代码应该显示 listeners 数组每个部分的读数。

# -*- coding: utf-8 -*-

class AbstractWeatherTower:
    def register(self, listener):
        raise NotImplementedError("Must subclass me")

    def unregister(self, listener):
        raise NotImplementedError("Must subclass me")

    def notify_listeners(self, event):
        raise NotImplementedError("Must subclass me")

class AbstractWeatherListener:
    def __init__(self, name, subject):
        self.name = name
        tower.register(self)

    def notify(self, event):
        raise NotImplementedError("Must subclass me")

class WeatherTower(AbstractWeatherTower):
    def __init__(self):
        self.listeners = []
        self.data = None

    def getUserAction(self):
        self.data = raw_input(‘Enter Pressure,Temperature,WindDirection:’)
        return self.data

    # Implement abstract Class AbstractSubject

    def register(self, listener):
        self.listeners.append(listener)

    def unregister(self, listener):
        self.listeners.remove(listener)

    def notify_listeners(self, event):
        for listener in self.listeners:
            listener.notify(event)

class PressureListener(AbstractWeatherListener):
    def notify(self, event):
        print self.name, "Current Barometric Pressure is ", event.split(“,”)[0], "atms"

class TemperatureListener(AbstractWeatherListener):
    def notify(self, event):
        print self.name, "The Temperature is: ", event.split(",")[1], "degrees F"

class WindListener(AbstractWeatherListener):
    def notify(self, event):
        print self.name, "The Wind Direction is from the ", event.split(“,”)[2].capitalize()


if __name__=="__main__":
    # make a subject object to spy on
    tower = WeatherTower()

    # register two listeners to monitor itT
    listenerT = TemperatureListener("<listener T>", tower)
    listenerP = PressureListener("<listener P>", tower)
    listenerW = WindListener("<listener W>", tower)

    # simulated event
    tower.notify_listeners ("<event 1>")
    # outputs:
    #     <listener T> received event <event 1>
    #     <listener P> received event <event 1>
    #     <listener W> received event <event 1>

    action = tower.getUserAction()
    tower.notify_listeners(action)
    #Enter something to do:hello
    # outputs:
    #     <listener T> received event hello
    #     <listener P> received event hello
    #     <listener W> received event hello

这是你的名言。他们很有趣。删除它们并输入正常的。

您在这里使用 U+2018 and U+2019 而不是 ASCII 单引号或双引号,因此出现语法错误。

此处引用错误:

event.split(“,”)
self.data = raw_input(‘Enter Pressure,Temperature,WindDirection:’)

这应该是;

self.data = raw_input('Enter Pressure,Temperature,WindDirection:')

self.data = raw_input("Enter Pressure,Temperature,WindDirection:")

您使用了错误的引号。