Python Forum

Full Version: Python seems to be randomly blowing up
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've been getting this weird error that seems to be unfounded:
# class.py
class Name(Parent):
    def __init__(self, dictionary):
        self.dictionary = dictionary
    .
    .
    .

# loaded_file.py
from . import class.py

dictionary = {...}
ClassName = Name(dictionary)
Here's the error:

TypeError: __init__() missing 1 required positional argument: 'dictionary'

Adding two print statements, like this:
# class.py
class ...
    def __init__(dictionary):
        print(dictionary)
        self.dictionary = dictionary
        print(self.dictionary)
    .
    .
    .
yields the same error, with the passed-in dictionary being printed out. Can anyone explain this to me?
(Aug-22-2018, 09:15 PM)parmort Wrote: [ -> ]def __init__(dictionary):
Are you actually not including self, or did you not copy/paste correctly?
I am not including self.
(Aug-22-2018, 09:15 PM)parmort Wrote: [ -> ]
    def __init__(dictionary):
        print(dictionary)
        self.dictionary = dictionary
You should be getting an error, about how self isn't defined, then.
Sorry, I read the question wrong. I am including self, something like
def __init__(self, dictionary):
(Aug-22-2018, 09:15 PM)parmort Wrote: [ -> ]
class Name(Parent):
    def __init__(self, dictionary):
        self.dictionary = dictionary

Alright, let's try this. What's the Parent look like, and are you calling it's __init__ method, with whichever arguments it expects?
The parent is an API-like class, with a bunch of user-over-writable methods. It doesn't have an __init__ method, however.

class Parent(object):
Know what (I should have done this earlier), here's the repo/commit.