Error de sangría de Python:

He intentado con notepad ++ y eclipse, pero incluso entonces, me está mostrando un error de sangría en la línea 18. No sé, ¿por qué me está lanzando un error como ese …? por favor, ayúdame.

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() 

Son sus citas por ejemplo en línea:

 self.lineEdit.setText('My Generic Device Name') 

prueba esto:

 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() 

En tales casos, suele ser una buena idea ejecutar python con el indicador -t :

-t: emite advertencias sobre el uso incoherente de tabs (-tt: errores de emisión)

Esto ayudará a encontrar problemas de sangrado causados ​​por tabs usadas accidentalmente.

La fila

  self.verticalLayout.addWidget(self.lineEdit) 

Debería estar en el mismo nivel de las otras filas.

Puede que te esté perdiendo porque tu editor mezcla tabs y espacios.

Si hace clic en “editar” en su propia pregunta, verá que esta fila no está sangrada correctamente.

Parece que estás usando la comilla incorrecta. Necesitas usar ' , no ' .

Aunque no estoy seguro de si este es tu problema.