Re: Problem when instantiating sub-class of owl.Thing

Posted by Jiba on
URL: http://owlready.306.s1.nabble.com/Problem-when-instantiating-sub-class-of-owl-Thing-tp1659p1667.html

Hi,

Owlready uses the __new__() special method for initializing object. The default __new__() handles keyword arguments, but not non-keyword arguments as you are using.

There are 2 solutions :

1) you can use keyword arguments, for example:

my_invoice = invoice_cls(doc_id = 'IN-1234', location = 'New York', color = 'blue', size = 'big')

2) you can override __new__(), as following:

    class BusinessDocument(Thing):
        def __new__(Class, doc_id, location, doc_type, color, size):
            Thing.__new__(Class)

        def __init__(self, doc_id, location, doc_type, color, size):
            self.doc_id = doc_id
            self.location = location
            self.doc_type = doc_type
            self.color = color
            self.size = size

And the same for the other classes.

Jiba