所以我有这个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:’)
^
我一直在尝试并试图弄清楚为什么首先会出现语法错误,也许这是一件非常简单的事情,我不会这样做。该代码应该显示侦听器数组的每个部分的读数。
# -*- 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
答案 0 :(得分:1)
答案 1 :(得分:0)
这是你的报价。他们很有趣。删除它们并输入正常的。
答案 2 :(得分:0)
self.data = raw_input(‘Enter Pressure,Temperature,WindDirection:’)
这应该是;
self.data = raw_input('Enter Pressure,Temperature,WindDirection:')
或
self.data = raw_input("Enter Pressure,Temperature,WindDirection:")
您使用的是错误的引号。