I am new to object-oriented programming in Python and have what seems to be a simple question and need some guidance.
If I have the following object myclass which is being initilized with self and a file path fname:
class myclass(object):
def __init__(self, fname):
self.fname = fname
self.title = None
self.geo_list = []
Everything seems to work.
a = myclass('a')
a has the three properties specified in __init__.
But If I add a line to check to make sure fname is not blank or None:
class myclass(object):
def __init__(self, fname):
self.fname = fname
self.title = None
self.geo_list = []
if self.fname == '' or self.fname is None:
raise AttributeError('Filename passed is blank.')
I get the NameError:
name 'self' is not defined