Re: testing for valid reference: obj vs. None!=obs vs. obj is not None

2006-12-08 Thread alf
alf wrote: > Hi, > > I have a reference to certain objects. What is the most pythonic way to > test for valid reference: > > if obj: > > if None!=obs: > > if obj is not None: > thx for all answers - now "if obj is not None:" in an obvious choice ... -- http://mail.python.org/mail

Re: testing for valid reference: obj vs. None!=obs vs. obj is not None

2006-09-11 Thread Gabriel Genellina
At Monday 4/9/2006 17:02, alf wrote: I have a reference to certain objects. What is the most pythonic way to test for valid reference: By "valid reference" you mean, you have initially: obj = None and you want to detect whether obj is bound to another, different, object, right? if

Re: testing for valid reference: obj vs. None!=obs vs. obj is not None

2006-09-05 Thread Bruno Desthuilliers
Carl Banks wrote: > Bruno Desthuilliers wrote: >> In python, assignement is a statement, not an expression, so there's no >> way you could write 'if obj = None' by mistake (-> syntax error). So >> this style is unpythonic. Also, None is a singleton, and identity test >> is way faster than equality

Re: testing for valid reference: obj vs. None!=obs vs. obj is not None

2006-09-04 Thread Paul Rubin
alf <[EMAIL PROTECTED]> writes: > I have a reference to certain objects. What is the most pythonic way > to test for valid reference: If you're intending to use None as a sentinel for an invalid reference, then use > if obj is not None: You could also make a unique sentinel: Sentine

Re: testing for valid reference: obj vs. None!=obs vs. obj is not None

2006-09-04 Thread Carl Banks
Bruno Desthuilliers wrote: > In python, assignement is a statement, not an expression, so there's no > way you could write 'if obj = None' by mistake (-> syntax error). So > this style is unpythonic. Also, None is a singleton, and identity test > is way faster than equality test. Playing Devil's a

Re: testing for valid reference: obj vs. None!=obs vs. obj is not None

2006-09-04 Thread Sandra-24
alf wrote: > Hi, > > I have a reference to certain objects. What is the most pythonic way to > test for valid reference: > > if obj: > > if None!=obs: > > if obj is not None: I like this way the most. I used timeit to benchmark this against the first one, expecting it to be fast

Re: testing for valid reference: obj vs. None!=obs vs. obj is not None

2006-09-04 Thread BJörn Lindqvist
> I have a reference to certain objects. What is the most pythonic way to > test for valid reference: > > if obj: > > if None!=obs: > > if obj is not None: The third way is the most precise way. It is often used in combination with default arguments. def __init__(self, amo

Re: testing for valid reference: obj vs. None!=obs vs. obj is not None

2006-09-04 Thread Bruno Desthuilliers
alf a écrit : > Hi, > > I have a reference to certain objects. What is the most pythonic way to > test for valid reference: > > if obj: Don't do this: for o in [0, '', [], {}, ()]: print obj, bool(obj), obj is None > if None!=obs: In python, assignement is a statement, not an exp

Re: testing for valid reference: obj vs. None!=obs vs. obj is not None

2006-09-04 Thread Carl Banks
alf wrote: > Hi, > > I have a reference to certain objects. What is the most pythonic way to > test for valid reference: > > if obj: > > if None!=obs: > > if obj is not None: If you're checking whether an object is None or not, the third is the best way. Some people might say y