Ianny Carolino
Ianny Carolino

Reputation: 1

Python class has no attribute when calling function

I have this kind of problem attributeError: module 'ResponseLayer' has no attribute 'RS'. I am a beginner just started learning python from scratch. What do i need to understand here? Am i wrong coding this?

class ResponseLayer:

    def RS(self,_width, _height, _step, _filter):
        self.width = _width
        self.height = _height
        self.step = _step
        self.filterr = _filter

class FastHessian:

    import ResponseLayer

    def buildResponseMap():
        responseMap = []

        w = int(img.Width / init)
        h = int(img.Height / init)
        s = int(init)

        if (octaves >=1):
            responseMap.append(RS(w, h, s, 9))
            responseMap.append(RS(w, h, s, 15))
            responseMap.append(RS(w, h, s, 21))
            responseMap.append(RS(w, h, s, 27))

Upvotes: 0

Views: 169

Answers (1)

mfonism
mfonism

Reputation: 573

Ianny,

If all the code you've shown live in the same file, then you don't have to import ResponseLayer.

I believe you're adding unique instances of ResponseLayer to a response map.

If I am correct, then you should change that RS method on ResponseLayer class to an instance creation method (init in Python).

So that you just write ResponseLayer(20, 30, 2, 4) to create an example response layer object.

This is what I mean:


class ResponseLayer:

    def __init__(self, width, height, step, _filter):
        self.width = width
        self.height = height
        self.step = step
        self._filter = _filter

class FastHessian:

    def buildResponseMap():
        responseMap = []

        w = int(img.Width / init)
        h = int(img.Height / init)
        s = int(init)

        if (octaves >= 1):
            responseMap.append(ResponseLayer(w, h, s, 9))
            responseMap.append(ResponseLayer(w, h, s, 15))
            responseMap.append(ResponseLayer(w, h, s, 21))
            responseMap.append(ResponseLayer(w, h, s, 27))

I understand you are a Python beginner.

Welcome to the world of Python.

I love helping beginners level up in my areas of strength. Like @chepner mentioned, your code looks too Java for Python. I would love to help you rewrite it to be more Pythonic. Feel free to chat me up here on StackOverflow.

Upvotes: 1

Related Questions