Python indentation error:
我已经尝试过notepad ++和eclipse但是即便如此,它在第18行显示了一个缩进错误。我不知道,为什么它会给我一个像这样的错误......? 请帮我。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | from brisa.core.reactors.qtreactor import QtReactor reactor = QtReactor() from brisa.core import config from brisa.upnp.device import Device from brisa.upnp.device.service import Service, StateVariable class QtDevice(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.verticalLayout = QtGui.QVBoxLayout(self) self.title = QtGui.QLabel("Qt Simple Device") font = QtGui.QFont() font.setPointSize(15) self.title.setFont(font) self.title.setAlignment(QtCore.Qt.AlignCenter) self.verticalLayout.addWidget(self.title) self.lineEdit = QtGui.QLineEdit(self) self.verticalLayout.addWidget(self.lineEdit) self.search_btn = QtGui.QPushButton("Start Device", self) self.verticalLayout.addWidget(self.search_btn) QtCore.QObject.connect(self.search_btn, QtCore.SIGNAL("clicked()"), self.start) self.stop_btn = QtGui.QPushButton("Stop Device", self) self.verticalLayout.addWidget(self.stop_btn) QtCore.QObject.connect(self.stop_btn, QtCore.SIGNAL("clicked()"), self.stop) self.lineEdit.setText(’My Generic Device Name’) self.root_device = None self.upnp_urn = ’urn:schemas-upnp-org:device:MyDevice:1’ def _add_root_device(self): project_page = ’http://brisa.garage.maemo.org’ serial_no = config.manager.brisa_version.replace(’.’, ’’).rjust(7, ’0’) self.root_device = Device(self.upnp_urn,str(self.lineEdit.text()), manufacturer=’’, manufacturer_url=, model_description=’ ’ model_name=’’, model_number=, model_url=, serial_number=) def _add_services(self): service_name = ’MyService’ service_type = ’urn:schemas-upnp-org:service:MyService:1’ myservice = Service(service_name, service_type, ’’) var = StateVariable(self,"A_ARG_TYPE_Variable",True, False,"string") myservice.add_state_variable(var) self.root_device.add_service(myservice) def _load(self): self._add_root_device() self._add_services() def start(self): self.stop() self._load() self.root_device.start() reactor.add_after_stop_func(self.root_device.stop) def stop(self): if self.root_device: self.root_device.stop() self.root_device = None def main(): qt_dev = QtDevice() qt_dev.show() reactor.main() if __name__ == ’__main__’: main() |
在这种情况下,使用
-t : issue warnings about inconsistent tab usage (-tt: issue errors)
这将有助于查找由意外使用的标签引起的缩进问题。
排
1 | self.verticalLayout.addWidget(self.lineEdit) |
应该在其他行的同一级别上。
您可能会错过它,因为您的编辑器混合了制表符和空格。
如果您在自己的问题中单击"编辑",您将看到此行未正确缩进。
这是你的报价,例如在线:
1 | self.lineEdit.setText(’My Generic Device Name’) |
试试这个:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | from brisa.core.reactors.qtreactor import QtReactor reactor = QtReactor() from brisa.core import config from brisa.upnp.device import Device from brisa.upnp.device.service import Service, StateVariable class QtDevice(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.verticalLayout = QtGui.QVBoxLayout(self) self.title = QtGui.QLabel("Qt Simple Device") font = QtGui.QFont() font.setPointSize(15) self.title.setFont(font) self.title.setAlignment(QtCore.Qt.AlignCenter) self.verticalLayout.addWidget(self.title) self.lineEdit = QtGui.QLineEdit(self) self.verticalLayout.addWidget(self.lineEdit) self.search_btn = QtGui.QPushButton("Start Device", self) self.verticalLayout.addWidget(self.search_btn) QtCore.QObject.connect(self.search_btn, QtCore.SIGNAL("clicked()"), self.start) self.stop_btn = QtGui.QPushButton("Stop Device", self) self.verticalLayout.addWidget(self.stop_btn) QtCore.QObject.connect(self.stop_btn, QtCore.SIGNAL("clicked()"), self.stop) self.lineEdit.setText('My Generic Device Name') self.root_device = None self.upnp_urn = 'urn:schemas-upnp-org:device:MyDevice:1' def _add_root_device(self): project_page = 'http://brisa.garage.maemo.org' serial_no = config.manager.brisa_version.replace('.', '').rjust(7, '0') self.root_device = Device(self.upnp_urn,str(self.lineEdit.text()), manufacturer='', manufacturer_url=, model_description=' ' model_name='', model_number=, model_url=, serial_number=) def _add_services(self): service_name = 'MyService' service_type = 'urn:schemas-upnp-org:service:MyService:1' myservice = Service(service_name, service_type, '') var = StateVariable(self,"A_ARG_TYPE_Variable",True, False,"string") myservice.add_state_variable(var) self.root_device.add_service(myservice) def _load(self): self._add_root_device() self._add_services() def start(self): self.stop() self._load() self.root_device.start() reactor.add_after_stop_func(self.root_device.stop) def stop(self): if self.root_device: self.root_device.stop() self.root_device = None def main(): qt_dev = QtDevice() qt_dev.show() reactor.main() if __name__ == '__main__': main() |
看起来你使用了错误的单引号。 您需要使用
不确定这是不是你的问题。