What's more pythonic?

Dan Stromberg strombrg at dcs.nac.uci.edu
Wed Sep 13 00:08:04 EDT 2006


Is sample1 or sample2 the more pythonic way of comparing?

class sample1
	def __init__(self, a, b):
		self.a = a
		self.b = b
	def __cmp__(self, other):
		return self.a.__cmp__(other.a)

...or:

class sample2
	def __init__(self, a, b):
		self.a = a
		self.b = b
	def __cmp__(self, other):
		if self.a < other.a:
			return -1
		elif self.a > other.a:
			return 1
		else:
			return 0

?

Thanks!




More information about the Python-list mailing list