python - Getting variable from other class -


as totally beginner need ask help. defined class config take config.ini file information , put them variable. define class : connection, base of result class config. trying many ways, give up. take ?

class config:     def __init__(self,system):            self.config = configparser.configparser()         self.config.read("config.ini")         self.connection_source=self.config.get(system,'source')         self.system=system      def getsystemsources(self):         return self.connection_source      def getconnection(self,source):         self.source=source         self.connection_string=self.config.get('connection',self.system+'_'+source+'_'+'connectstring')   ## connection         self.connection_user=self.config.get('connection',self.system+'_'+source+'_'+'user')   ## connection user         self.connection_password=self.config.get('connection',self.system+'_'+source+'_'+'password')   ## connection pass    class connection(config):     def __init__ (self):         self.connection_string=config.connection_string         self.connection_user=config.connection_user         self.connection_password=config.connection_user         self.connection_source=config.connection_source     def conn_function(self):         print (self.connection_string)         print (self.connection_user)         print (self.connection_password)  emp1 = config('windows')     value=emp1.getsystemsources()    print (value)    emp2 = connection()    -> how run ?  

you pass config object __init__ function

class config:     def __init__(self,system):            self.config = configparser.configparser()         self.config.read("config.ini")         self.connection_source=self.config.get(system,'source')         self.getconnection(self.connection_source)         self.system=system  class connection(config):     def __init__ (self, system):         config.__init__(self, system)  emp1 = connection('windows') emp1.conn_function() 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -