[CentralOH] A simple class to provide named fields

Steven Huwig steven_h at acm.org
Thu Jan 17 00:06:47 CET 2008


On Jan 16, 2008, at 4:28 PM, Brandon Mintern wrote:
>
> class Fields:
>     """
>     A class intended to provide a simple interface for creating  
> objects
>     with named fields. That is, instead of returning a tuple and  
> indexing
>     it or writing a unique class, you can simply do something like:
>     a = Fields(x=1, y=2)
>     a.x # 1
>     a.y # 2
>     """
>     def __init__ (self, **kwargs):
>         for name, value in kwargs.iteritems():
>             self.__dict__[name] = value
>

I like it! My only suggestion would be to name it "Record" instead of  
"Fields", following the description at http://en.wikipedia.org/wiki/ 
Record_(computer_science).

-- Steve


More information about the CentralOH mailing list