Skip to content Skip to sidebar Skip to footer

Accessing Variable Outside Class Using Inheritance

I am trying to inherit a variable from base class but the interpreter throws an error. Here is my code: class LibAccess(object): def __init__(self,url): self.url = url

Solution 1:

You will need to define self.urllib_data prior to accessing it. The simples way would be to create it during initialization, e.g.

classLibAccess(object):
    def__init__(self,url):
        self.url = url
        self.urllib_data = None

That way you can make sure it exists everytime you try to access it. From your code I take it that you do not want to obtain the actual data during initialization. Alternatively, you could call self.url_lib() from __init__(..) to read the data for the first time. Updating it later on would be done in the same way as before.

Post a Comment for "Accessing Variable Outside Class Using Inheritance"