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

Gabriel Genellina gagsl-py at yahoo.com.ar
Tue Sep 12 00:19:56 EDT 2006


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 obj:

This checks whether obj is considered True, not whether it is None. 
e.g. obj=[] would not pass.

>         if None!=obs:

Would be OK, but the next one is better:

>         if obj is not None:

This is what you are looking for! :)



Gabriel Genellina
Softlab SRL 


	
	
		
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas




More information about the Python-list mailing list