Newbie can't figure out documentation practices

Fernando Perez fperez528 at yahoo.com
Fri May 9 14:28:09 EDT 2003


Sean Ross wrote:

> Here's one way:
> 
> class MyClass:
>     def __init__(self, z):
>         self.z = z
>     def test(self, other):
>         info = \
> """
> 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
> """
>         x, y = 3, 4
>         infodict = locals().copy()
>         infodict.update(dict([('self.z', self.z), ('other.z', other.z)]))
>         print info % infodict

Thanks for the idea. But the problem with this approach is that it still
requires manual copies of all the variables.  If I'm going to have to build
explicitly all of this, I may as well use simple temporaries.

My point in all of this is that python, while overall incredibly clean in
its design, lacks an easy way of accessing object member data for string
interpolation.  Considering how object-oriented python is, this strikes me
as a big wart.  But I'm willing to be convinced otherwise, so I keep
listening :)

Cheers,

f.





More information about the Python-list mailing list