__init__ TypeError

doing ‘The Enigma Machine - Part 1: The Plugboard’ in codewars
not understanding the error…

TypeError: init() takes exactly 2 arguments (1 given)

import sys

class Plugboard(object):
    def __init__(self, wires):
        wires: This is the mapping of pairs of characters
        if len(wires) > 10:
        self.wire = wires
    def get_wires(self):
        return self.wire
    def process(self, c):
        c: The single character to process
        self.c = c
        if c in self.wire:
            if self.wire.index(c) % 2 == 0:
                return self.wire[self.wire.index(c) + 1]
                return self.wire[self.wire.index(c) - 1]
        return c

step 2 of the instructions:

Validate that the wire pairings are legitimate. Raise an exception if not.

Looking at your code, i don’t see you raise an exception anywhere?


Oh, right. no need to exit the code…

yep, you shouldn’t exit, you should raise an error. Raising an error is more common then exiting, given then the user using your program, knows what is wrong rather then the program just exit without a visible reason for them

if len(wires) > 10:
            raise ValueError("not valid plugboard")

still same error… ¯_ツ_/¯
how exactly?


one of the test cases by the cata creates an instance of Plugboard without an argument for wires (parameter of init method), this is what gives the type error, for this, you need to raise an exception


now it doesn’t accept me because I raised an error.

if wires not in globals():
    raise NameError("No plugboard")

Is there any difference between errors and exceptions?

who is solving the cata? You or me?

This is not the only verification you need to do, you need to verify the number of wires, no duplicate wires and so on.


seems I was asking too much.
ok, I’ll try