python - Sharing values between methods -


i thougth knew how use return in python came , dont understand it.

    class projet(object):        def pathdirectory(self):            pathdir= str(qfiledialog.getexistingdirectory(ui.pathtab1, 'select path','', qfiledialog.showdirsonly))            return pathdir         def gofunc(self, pathdir):           # function          # here pathdir boolean , not str path directory     if __name__ == "__main__":        p = projet()        pathdir = p.pathdirectory()        p.gofunc(pathdir) ## line begins 

so have function gets path directory in variable , return it. , want use path directory in other functions when call it, it's no longer string it's boolean (i false when print pathdir)

update : sorry guys, typing mistake, it's pathdir , not path, still returns false

this should work. rather passing variables unnecessarily, can create member variable of class. variable can updated , reused other function without having worry passing parameters.

class projet(object):      def pathdirectory(self):         print "- - in pathdirectory - -"         self.pathdir= str(qfiledialog.getexistingdirectory(ui.pathtab1, 'select path','', qfiledialog.showdirsonly))      def gofunc(self):         print "- - in gofunc - -"         print self.pathdir  if __name__ == "__main__":     p = projet()     p.pathdirectory()     p.gofunc() 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -