I think this is a great idea, but I would not want to introduce a new keyword. How about<div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace"> foo is in bar = hasattr(foo,bar)</font></div>
<div><div><font class="Apple-style-span" face="'courier new', monospace"> foo is not in bar = not hasattr(foo,bar)</font></div><div><br></div></div></div><div>But there are other common checks I do all the time that I would really like to have shortcuts for. Here are ways to do them without new keywords:</div>
<div><br></div><div><font class="Apple-style-span" face="'courier new', monospace"> foo is class bar = isinstance(foo,bar)</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> foo is from bar = issubclass(foo,bar)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> foo is with bar = type(foo) == type(bar)</font></div><div><div><br></div><div>Can we make an exception to the moratorium, just for today?</div>
<div><br>--- Bruce<br><a href="http://www.vroospeak.com">http://www.vroospeak.com</a><br>
<br><br><div class="gmail_quote">On Thu, Apr 1, 2010 at 8:15 AM, Robert Madole <span dir="ltr"><<a href="mailto:robmadole@gmail.com">robmadole@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
So I just wrote my 1-gazillionth "if hasattr('method', my_object):" and wanted badly to write this.<br>
<br>
if 'method' on my_object:<br>
<br>
I'm not the most experienced Python user, but as far as I can tell hasattr is the preferred way of checking if a method exists.<br>
<br>
Please correct me if there is a better way, otherwise I'd like to see what everyone thinks about an "on" statement being added to the Python language.<br>
<br>
Thanks,<br>
<br>
Rob Madole<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
</blockquote></div><br></div></div>