I am newbie in python OOPs programming. I stuck in one problem. I want to make class. I tried to write function in class. Now I want to call function in same class and want to store return value in variable within class.
Example:
class extract_user_profile(object):
#ukNames = []
def __init__(self,data,pdf_to_text_list,text_prop_dict,text_dict):
self.data = data
self.pdf_to_text_list = pdf_to_text_list
self.text_prop_dict = text_prop_dict
self.text_dict = text_dict
def read_csv(input_file):
file = open(input_file, 'r')
reader = csv.reader(file)
return reader
def person_name_list(self,dir_path):
file_name = 'uknames.csv'
reader = self.read_csv(dir_path + file_name)
name_list = []
for row in reader:
name_list.append(row[0].lower())
return name_list
dir_path = "/Users/imac086/Documents/premal/projects_Quix/CV_parsing/ResumeParser-master/"
u = person_name_list(dir_path) # I want to call person_name_list function in class
def getName():
for i in u: # I want to use u variable which I get from above. and this is in to the class
print(u)
here I created two function in class now I want to call person_name_list
function within class and store return value in variable within class. Like below I tried without class.
u = person_name_list(dir_path)
so here u
variable have contain return value of person_name_list. those values I want to use in remaining functions.
I tired to use and call function like
u = self.person_name_list(self,dir_path)
I wrote self because I call read_csv file in that function also. it gives me error below:
NameError: name 'self' is not defined
So How can I do that? Please let me know. If I make any mistake in question please forgive me.