[Tutor] Dynamic variables names to objects of the same class ?

K Dhanvi dhanvik at cybage.com
Fri Aug 22 14:40:24 EDT 2003

Dear friends,

 I have a query about giving names to variables inside classes and thus to
the objects of the classes..

 I have a class called configReader which reads a configuration file and
then puts the configuration data into a dictionary at prsent. Before reading
the configuration file, the config object is told what keys to expect and
their datatpyes for simple santiy checks on the corresonding values.. At
present the key and values are stored in a dictionary.. I would like to make
each key a property of the respective configReader object.
  for example. If one of my keys in the configuration file is MAX_THREADS..
I would like my code to be as follows
        import ConfigReader
        config = ConfigReader( "./config.file")
        config.AddKey( "MAX_THREADS", INT )

        noOfThreads = config.MAX_THREADS

The first 3 lines of the sample code have been completed.. I would like to
add the functionality similar to the final line of the sample code. Each
object willl have different properties in itself depending upon the keys it
was initialized with. i.e there could be another config object which will
access another property "REGISTRATION_CURVE"..

please lemme  know if theres any way this can be achieved in Python ?

Thank you for your time and help :)


More information about the Tutor mailing list