I am making a GUI in PyQt and need to connect the graphic creation classes and methods of my script with its analytics class methods. I've tried doing this by simply calling the analytics method from within the graphic method (as seen below) but this results in a "global name 'UsersPerPlatform' is not defined" error so this clearly doesn't pull the dictionary from the other method.
return UsersPerPlatform #both are dictionaries
class UsersPlatformPie(MyMplCanvas): #irrelevant parent
Analytics.UsersPerCountryOrPlatform() #running function to return UsersPerPlatform
for p, c in UsersPerPlatform:
print 'If I could access the UsersPerPlatform dictionary I would plot something!'
You cannot access local namespace from called function - but you can easily access return value from any called function.
class Analytics: @staticmethod def UsersPerCountryOrPlatform(): ... return UsersPerCountry, UsersPerPlatform class UsersPlatformPie: def compute_figure(self): myUsersPerCountry, myUsersPerPlatform = Analytics.UsersPerCountryOrPlatform() print(myUsersPerCountry) print(myUsersPerPlatform)