Re: sys.maxint in Python 3

2008-04-21 Thread castironpi
On Apr 21, 5:20 pm, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:
> > In some algorithms a sentinel value may be useful, so for Python 3.x
>
> Better to just use object() to generate sentinels.

Infinity is a number that compares always like.
--
http://mail.python.org/mailman/listinfo/python-list


Re: sys.maxint in Python 3

2008-04-21 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> In some algorithms a sentinel value may be useful, so for Python 3.x

Better to just use object() to generate sentinels.
--
http://mail.python.org/mailman/listinfo/python-list


Re: sys.maxint in Python 3

2008-04-21 Thread Christian Heimes
[EMAIL PROTECTED] schrieb:
> In some algorithms a sentinel value may be useful, so for Python 3.x
> sys.maxint may be replaced by an improvement of the following infinite
> and neginfinite singleton objects:

Python 3.0 doesn't have sys.maxint any more since Python 3's ints are of
arbitrary length. Instead of sys.maxint it has sys.maxsize; the maximum
size of a positive sized size_t aka Py_ssize_t.

Christian
-- 
http://mail.python.org/mailman/listinfo/python-list


sys.maxint in Python 3

2008-04-21 Thread bearophileHUGS
In some algorithms a sentinel value may be useful, so for Python 3.x
sys.maxint may be replaced by an improvement of the following infinite
and neginfinite singleton objects:

class Infinite(object):
def __repr__(self): return "infinite"
def __cmp__(self, other):
if other is infinite: return 0
if other is neginfinite: return 1
other + 1 # type control
return 1
infinite = Infinite()

class NegInfinite(object):
def __repr__(self): return "neginfinite"
def __cmp__(self, other):
if other is neginfinite: return 0
if other is infinite: return -1
other + 1 # type control
return -1
neginfinite = NegInfinite()

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list