functions, list, default parameters

Mark Wooding mdw at distorted.org.uk
Sat Nov 6 15:57:06 EDT 2010


Dennis Lee Bieber <wlfraed at ix.netcom.com> writes:

> On Sat, 06 Nov 2010 12:37:42 +0000, mdw at distorted.org.uk (Mark Wooding)
> declaimed the following in gmane.comp.python.general:
>
> > 
> > Two reasons.  Firstly, this comes from my Lisp background: making a
> > list is the obvious way of producing an unforgeable object.
> > Secondly, if you see an objects that prints as ['missing'], you have
> > a chance of working out where it came from; for a loose object()
> > that's kind of hard without a wabbit hunter.
> >
> 	I think the Python form is to create a basic class instance, a la
>
> >>> class Sentinal(object):
> ... 	pass
> ... 
> >>> _missing = Sentinal()
> >>> print _missing
> <__main__.Sentinal object at 0x011F01B0>

No, that doesn't tell me where it came from at all.  Given a thingy that
prints like that, I still need a wabbit hunter to tell me what /this/
particular sentinel value means.

> 	Or, if one wants to get fancier (maybe stuff the class definition
> into some common package)
>
>
> >>> class Sentinal(object):
> ... 	def __init__(self, text):
> ... 		self.text = text
> ... 	def __str__(self):
> ... 		return "%s : %s" % (repr(self), self.text)
> ... 
> >>> _missing = Sentinal("Missing Items")
> >>> print _missing
> <__main__.Sentinal object at 0x0120D070> : Missing Items

And the advantage of all of this typing over ['missing'] is what,
precisely?  If I want to write Java, I know where to look; I don't.

-- [mdw]



More information about the Python-list mailing list