我推動了有關此錯誤的主題,並且存在空間錯誤的問題。 在我的問題不是我加X = 2以下even_or_odd與if x == 1 :
的問題,它拋出由於IndentationError,無法寫入新行:意外縮進Python
Traceback (most recent call last):
File "server.py", line 16, in <module>
from router import RouteLayer
File "/home/pi/whatsapp-bot-seed/src/router.py", line 13, in <module>
from views.super_kacper import SuperKacper
File "/home/pi/whatsapp-bot-seed/src/views/super_kacper.py", line 25
xd = 2
^
IndentationError: unexpected indent
碼/
from utils.media_sender import UrlPrintSender
from yowsup.layers.protocol_messages.protocolentities.message_text import TextMessageProtocolEntity
import random
class SuperKacper():
def __init__(self, interface_layer):
self.interface_layer = interface_layer
self.url_print_sender = UrlPrintSender(self.interface_layer)
self.routes = [
("/(?P<evenOrOdd>even|odd)$", self.even_or_odd),
]
def even_or_odd(self, message=None, match=None, to=None):
is_odd = len(match.group("evenOrOdd")) % 2
test = 2 #<<<<<<<<<<When I add someting, here test = 2
num = random.randint(1, 10)
if (is_odd and num % 2) or (not is_odd and not num % 2):
return TextMessageProtocolEntity("[%d]\nYou win." % num, to=message.getFrom())
else:
return TextMessageProtocolEntity("[%d]\nYou lose!" % num, to=message.getFrom())
您的發佈代碼似乎正確縮進。我會檢查你的python文件中的一個。 – Leb
我的python文件中的哪個文件Oo – Kaczper
router.py完全是wr wr – Kaczper