I want to have a function that wraps and object in an iterable one in order to allow the clients of the function treat the same way collections and single objects, i did the following:

 def to_iter(obj):
     try:
         iter(obj)
         return obj
     except TypeError:
         return [obj]

Is there a pythonic way to do this?, what if obj is a string and i want to treat strings as single objects?, should i use isinstance instead iter?

Edit
Report