Import data from function to other on python?

Question:

This is my example code …

ImagePath = '/home/logs'

def askForTarget(self, source):
        getname = source[1].rstrip()
        image_path = ImagePath + getname
        self.session.openWithCallback(self.doExt, VirtualKeyBoard, title=_("Please Enter Name For Image"), text=" ")

def doExt(self, target):
        if target is None:
            return
        else:
            image_name = target
            image_path2 = self.image_path
            self.session.open(doBackUpExternal, image_name, image_path2)

def doBackUpExternal(self):
        # Some codes here for do other job

I need to print image_path2 from doExt … But I have got error ..

image_path2 = image_path
              ^^^^^^^^^
AttributeError: object has no attribute 'image_path'

How to fix it ?!!!

Asked By: Fair Bird

||

Answers:

Do you have a class? I see self param in methods but I can’t see the class. However, I think you are forgetting the self keyword while creating image_path variable, try this

def askForTarget(self, source):
        getname = source[1].rstrip()
        self.image_path = ImagePath + getname
        self.session.openWithCallback(self.doExt, VirtualKeyBoard, title=_("Please Enter Name For Image"), text=" ")

def doExt(self, image_name):
        if image_name is not None:
            self.session.open(doBackUpExternal, image_name, self.image_path)
Answered By: mamo
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.