[python-win32] python-win32 Digest, Vol 116, Issue 13

Paul_Koning at Dell.com Paul_Koning at Dell.com
Fri Nov 30 22:23:56 CET 2012


On Nov 30, 2012, at 4:20 PM, Tim Roberts wrote:

> In the future, I'd like to suggest that you choose a genuine subject
> line when you post.  It makes people more inclined to read your messages.
> 
> 
> Michael Wilson wrote:
>> 
>> My thought if there's not already an elegant solution in Python is to
>> create a flag 'r' before ranges. So, the example here would become
>> [1,3,'r',5,10,18,78]. Then I just do a  > < query to find a match. How
>> does that sound?
> 
> I can think of several approaches.  For a range, you could add a
> two-tuple instead of an integer:
>    nums = [1, 3, (5,10), 18, 78]
> You can tell the difference at runtime:
>    for item in nums:
>        if type(item) == tuple:

Nit: the Pythonic recommended way of doing this is "if isinstance (item, tuple):"

The difference is that this will also work if item is an instance of a subclass of "tuple" while the original code does not handle that case.  For this code, that might not be an interesting scenario, but in other places it might be.  It's worth getting into the habit of using "isinstance".

	paul




More information about the python-win32 mailing list