1st non-trivial program - gentle criticism requested

Gary D. Duzan gduzan at gte.com
Thu Apr 13 21:00:10 CEST 2000


Donn Cave wrote:
> 
> There's a builtin max() that I think can do the work of your findMax.
> 
> I have plenty of these in my programs:
> 
>    print "The alphabet is '" + gAlphabet + "'"
> 
> but today I prefer
> 
>    print "The alphabet is '%s'" % gAlphabet
> 
> because of the greater tolerance for objects that are not really
> strings but have string representations.  (OK, it's a string, but
> what will happen if you later change this object to something else?)

   Well, if you change it to a tuple, you're going to have problems,
anyway. If you really want to be more change-proof, you'll want:

    print "The alphabet is '%s'" % (gAlphabet,)

or:

    print "The alphabet is '%s'" % str(gAlphabet)

or:

    print "The alphabet is '" + str(gAlphabet) + "'"

This potential stumbling block makes me wonder if allowing the
singleton case was really wise.

					Gary Duzan
					GTE Laboratories



More information about the Python-list mailing list