[SAGA-RG] SAGA attributes as Python dictionaries?

Hartmut Kaiser hkaiser at cct.lsu.edu
Thu Nov 5 07:27:36 CST 2009


> > > > > It is certainly doable from the technical point of view. My
> > question
> > > > > is what would be the advantages of having a dict-like
> interface?
> > > > Would
> > > > > that be in this form then:
> > > >
> > > > If I rember the discussion from Banff correctly, the proposal was
> > > > more like
> > > >
> > > >   jobDescription.attributes["Executable"] = "/bin/hostname"
> > >
> > > Why not:
> > >
> > >    jobDescription["Executable"] = "/bin/hostname"
> >
> > Yes, I'd also prefer this. Much shorter, and it resembles that a job
> > description IS-A Attributes.
> 
> Well, I stand corrected, it _is_ possible by overloading
> __getattr__/__setattr__.

I got the context of my reply wrong. This comment was intended to be a reply
for:

> > >       jobDescription.attributes.Executable = "/bin/hostname"
> >
> > Not good as we have no way to ensure only proper attributes are
> accessed.
> > For instance
> >
> >       jobDescription.attributes.Executable1 = "/bin/hostname"
> >
> > will go unnoticed as Python simply creates a member Executable1
> assigning
> > the string.
> 
> Ah, I did not know this! Hmm, that would indeed be a very good reason
> not to use Python properties for attributes.

So here it goes again:

Well, I stand corrected, it _is_ possible by overloading
__getattr__/__setattr__.

Regards Hartmut

-------------------
Meet me at BoostCon
http://boostcon.com





More information about the saga-rg mailing list