Newbie can't figure out documentation practices

Fernando Perez fperez528 at yahoo.com
Fri May 9 14:07:53 EDT 2003


sismex01 at hebmex.com wrote:


> Hmmm... I'd first:
> 
>>>> def D(**args): return args
> 
> and then:
> 
> print """
> var x = %(x)s
> var y = %(y)s
> var self.z = %(self_z)s
> fun x+y+self.z = %(x)s+%(y)s+%(self_z)s
> var z from other object = %(other_z)s
> z from self plus other = %(self_z)s + %(other_z)s
> """ % D(x=..., y=..., self_z=self.z, other_z=other.z)
> 
> But, I think, I suspect that you don't like %(...)s

Actually, while I'm not exactly in love with them, it's ok for now.  My
problem with the above is that, if we are talking about many variables
(which I run into more often than I'd like), the D(x=.., y=....) call
becomes ridiculously long, error prone and plain ugly.  I think it's ugly
even for a few variables, but at least it's easy to get it right if it's
short.

Any other approaches/ideas/comments?

The fact that in such a cleanly object oriented language, there is no easy
way of accessing an object's member data for string interpolation (without
making zillions of temporary locals as above) strikes me as a _big_ wart. 
I'm known to be a rabid python fan, yet I still can't get over this thing. 
For some reason, it seems to bother me a lot more than most other python
users ;)

Cheers,

f.




More information about the Python-list mailing list