0

Question I want to compare a full name with the persons initials but, for some reason I keep getting this error. Any help will be greatly appreciated!

#check.py", line 27, in check_fn a = self.my_name AttributeError: 'Check' object has no attribute 'my_name' 
 import re 
 class Check(object): 
 def __init__(self, word): 
 self.word = word 
 def abbr(self): 
 e = self.word 
 w = self.word[:1] 
 lens = len(self.word) 
 last = self.word[-1:] 
 all = '%s%s%s' %(w, lens, last) 
 key_a = [] 
 key_b = [] 
 app_a = key_a.append(e) 
 app_b = key_b.append(all) 
 dictonary = dict(zip(key_a, key_b)) 
 self.check_fn(e, all) 
 return dictonary 
 def check_fn(self, my_name, intials): 
 a = self.my_name 
 b = self.intials 
 list_a = [] 
 list_b = [] 
 aa = list_a.append(a) 
 bb = list_b.append(b) 
 for element in list_a: 
 m = re.match("(^['%s' %(list_b)]\d)", element) 
 if m: 
 print(m.groups()) 
AliciaBytes
7,4796 gold badges38 silver badges47 bronze badges
asked Jun 15, 2016 at 11:16
1
  • in check_fn method, you are affecting self.my_name to "a", but my_name is not an attribute of check class Commented Jun 15, 2016 at 11:21

3 Answers 3

1

you've never defined self.my_name (or self.intials for that matter).

your code:

 a = self.my_name 
 b = self.intials 

did you want to have this code?

 a = my_name 
 b = intials 
answered Jun 15, 2016 at 11:20
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer what I want to do is pass the two variables in my check_fn function. so basically take e variable which is self.word then take all variable which is the initial and then pass it into my check_fn to see if any letters match. @DomTomCat
1

'self' points to the object of same class. Here my_name and initials are not defined in the class 'check'.

a = my_name 
b = intials 

As these parameters are passed through the function, the above snippet will work for you.

answered Jun 15, 2016 at 11:33

Comments

0

It's raising AttributeError because in the you haven't declared self.my_name or self.initials therefore your Check class hasn't got an attribute called my_name.

answered Jun 15, 2016 at 11:27

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.