[DICTIONARY] - Copy dictionary entries to attributes
remark: not sure if the term "dictionary" is correct here. I have the following situation: within a setup.cfg, settings are passed this way: settings=project_page=theProjectPage.com myVar=myValue those are accessible later like this: settings['project_page'] / settings['myValue'] - Now my question: is there any standard function to map the settings directly to attributes? something like: dictionary_make_attributes(settings) thus they can be accessed via: settings.project_page / settings.myVar or copy_dictionary_entries_to_attributes(vars, settings) vars.project_page / vars.myVar ? . -- http://lazaridis.com -- http://mail.python.org/mailman/listinfo/python-list
Re: [DICTIONARY] - Copy dictionary entries to attributes
Ilias Lazaridis schrieb: > remark: not sure if the term "dictionary" is correct here. > > I have the following situation: > > within a setup.cfg, settings are passed this way: > > settings=project_page=theProjectPage.com > myVar=myValue > > those are accessible later like this: > > settings['project_page'] / settings['myValue'] > > - > > Now my question: is there any standard function to map the settings > directly to attributes? > > something like: > > dictionary_make_attributes(settings) > > thus they can be accessed via: > > settings.project_page / settings.myVar > > or > > copy_dictionary_entries_to_attributes(vars, settings) > > vars.project_page / vars.myVar Either you use __getitem__, or the "bunch"-recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308 Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: [DICTIONARY] - Copy dictionary entries to attributes
Diez B. Roggisch wrote: > Ilias Lazaridis schrieb: >> remark: not sure if the term "dictionary" is correct here. >> >> I have the following situation: >> >> within a setup.cfg, settings are passed this way: >> >> settings=project_page=theProjectPage.com >> myVar=myValue >> >> those are accessible later like this: >> >> settings['project_page'] / settings['myValue'] >> >> - >> >> Now my question: is there any standard function to map the settings >> directly to attributes? >> >> something like: >> >> dictionary_make_attributes(settings) >> >> thus they can be accessed via: >> >> settings.project_page / settings.myVar >> >> or >> >> copy_dictionary_entries_to_attributes(vars, settings) >> >> vars.project_page / vars.myVar > > Either you use __getitem__, or the "bunch"-recipe: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308 > > Diez Looks intresting, but I am a newcomer to python. How would the __getitem__ implementation look like? . -- http://lazaridis.com -- http://mail.python.org/mailman/listinfo/python-list