0

I am trying to call a function in class A from One.py file in to Two.py file by using

 from one import A

in this class A :in init function i am assigning a variable name i.e; self._fname=name. Now i am trying to call a function funC() from class A which uses the self._fname varible like below in Two.py

 now=A()
 now.funC()

when call this function i am getting an Attribute Error :Class A has no attribute '_fname'

func():
if self._fname:
    print "found"

How can i resolve this problem.Is there any way that i can import Class A object from one.py to Two.py so by using that object i can access the 'fname' variable.

2
  • Please show actual code with the actual problem. The code snippets and the error message don't match. You show the call of funC but the (incomplete) definition of func(), func() accesses the attribute fname but the error message refers to _fname. It's hard to help here. Commented Dec 30, 2015 at 15:25
  • You've changed the attribute name in the code now but still haven't shown the actual code. Show enough code to enable us to reproduce the error. Commented Jan 7, 2016 at 14:37

1 Answer 1

0

AttributeError are typically raised when you try to access an attribute or member which is not defined in the object being dealt with. In your case, you are initializing self._fname and are trying to use self.fname, which in my opinion is not defined in your class 'A' (notice the underscore before 'fname') . so basically, if you try to access the correct member (self._fname) in func() ,your Attribute error would go away !

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.