0

I've readed topics about this error and there were problems with wrong spaces. In my problem aren't problems with if x == 1 : I've added x = 2 below even_or_odd and it throws

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

code /

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())
Kaczper
  • 103
  • 1
  • 2
  • 11
  • Your posted code seems to be indented properly. I would check the one in your python file. – Leb Mar 09 '16 at 18:10
  • Which file in my python file O.o – Kaczper Mar 09 '16 at 18:11
  • router.py is writed perfectly – Kaczper Mar 09 '16 at 18:12
  • The lines `("/(?Peven|odd)$", self.even_or_odd),` and `num = random.randint(1, 10)` uses tabs while the rest are using spaces – jonhopkins Mar 09 '16 at 18:13
  • @jonhopkins I don't think the problem is there, but you're right as far as mixing spaces and tabs is not a good idea. Choose one and stick to it http://stackoverflow.com/questions/120926/why-does-python-pep-8-strongly-recommend-spaces-over-tabs-for-indentation – Leb Mar 09 '16 at 18:14
  • @Leb thanks for the link. I didn't know you can get away with mixing tabs and spaces in python – jonhopkins Mar 09 '16 at 18:28
  • @jonhopkins no problem. I'm voting to close this because the problem can't be reproduced and SO is not a debugging service. – Leb Mar 09 '16 at 18:33

1 Answers1

0

You have bad indentation, delete blank space before this line and then use TAB to correct indentation, try it :)

sunny
  • 178
  • 3
  • 12