python - Accessing class methods inside another class at same scope -


trying work around getting access class method in class while being inside class. code below explain goal.

class access(object):      def __init__(self):         pass      def select(self, value):         store.keep(value)  class store(object):      def __init__(self):         self.store_value = 0      def keep(self, value):         self.store_value = value  x = access() y = store()  x.select(10)  y.store_value ##want output of 10 

i don't see way want without access having reference store object.

the closest thing can is

class access(object):      def __init__(self):         pass      def select(self, value):         store.keep(value)  class store(object):      @classmethod     def keep(cls, value):         cls.store_value = value  x = access() y = store()  x.select(10)  print y.store_value #will print 10   #but  z = store()  print z.store_value #will print 10 

where store_value shared instances of store.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -