string formatting with mapping & '*'... is this a bug?

Pierre Fortin pfortin at pfortin.com
Fri Sep 10 11:40:48 EDT 2004


On Fri, 10 Sep 2004 16:34:31 +0200 Alex wrote:

> Pierre Fortin <pfortin at pfortin.com> wrote:

> > PS:  Here's the latest incarnation of the test script...  for me, the
> > "voodoo" part is
> >          self.__dict__.update(locals())
> 
> Ah, sorry, my favourite idiom to avoid the boilerplate of
> 
>     def __init__(self, fee, fie, foo, fum):
>         self.fee = fee
>         self.fie = fie
>         self.foo = foo
>         self.fum = fum
> 
> Boilerplate is bad, and I'm keen on "Once, and ONLY once!" as a
> programming practice, so having to mention each of those names three
> times in totally repetitive ways makes me shiver.  My favourite idiom

I fully agree with "once and ONLY once"...  but you've pointed out that
"not-at-all is better than once"... :^)

> does, per se, leave a silly self.self around (which means a silly
> reference loop) so I should remember to 'del self.self' after it...

Since "self" is a convention (could use "this"), t'would be nice if Python
could avoid foo.foo ref. loops in a future release...

> >     map = dict(Date=Date,
> >                Open=float(Open),
> >                High=float(High),
> >                Low=float(Low),
> >                Close=float(Close),
> >                Volume=int(Volume),
> >                AdjClose=float(AdjClose),
> >                Change=change[int(float(AdjClose) >= float(Open)) +
> >                              int(float(AdjClose) == float(Open))]
> >                )
> 
> I could suggest some deboilerplatization here, too, but maybe that would
> be pushing things too far...

Hey! You're on a roll and I'm open for more abu... er education if this
isn't an imposition... :^) 

> No, print itself has nothing to do with it; % is left associative, so

Of course....  lack of sleep triggered that faulty logic...

> Come to think of that, you SHOULD hoist the "real format" out of the
> loop,

That's a given in my book... :>

> it IS a Python oddity that True+False
> equals 1;-).

That's OK with me...  it was True+True equals *1* (OR v. +) that forced me
to wrap them with int()'s 

Take care,
Pierre



More information about the Python-list mailing list