1

When working in my plugin's main python function, I receive an AttributeError anytime I call a class method from within the class itself.

For example the sample code below:

class PluginName:
    def __init__(self, iface):
        ...
        self.do_something()

    def do_something(self):
        ...

Would result in the error: AttributeError: PluginName instance has no attribute 'do_something'

Shouldn't do_something() be recognized as a method rather than an attribute because of the parentheses?

  • Please share a code snippet that shows how you are using this method so that I can pinpoint what is actually causing this error. – Asad Abbas May 3 '18 at 4:27
1

I was getting the same error for a long time, I am new to this, but in my function when I remove the underscores from the function name it works fine. I figured underscores are treated in some different way in django.

def getname(self):
    return self.name

def getname1(self):
    return self.name

def lastseen(self):
    return cache.get('seen_%s' % (self.user.username))



def last_seen(self):
    return cache.get('seen_%s' % (self.user.username))

The .last_seen() doesn't work, The .lastseen() does, The .getname1() doesn't work, The .getname() does.

To be honest I don't know if anyone does I would love to know why. Thanks

0

The same error happends when also, as an example:

You have a variable in the constructor called "X" and you use it in "do_something" function but u define it after calling the function in the constructor, like:

def __init__(self, iface):
        ...
        self.do_something()
        self.x = 0

def do_something(self):
        self.x = 1 <------- you will get the error here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.