• [^] # Re: Le titre est trop long

    Posté par (site web personnel) . En réponse au journal Typage statique versus typage dynamique. Évalué à 0. Dernière modification le 10 juillet 2012 à 13:58.

    def function(input):
     """
     Take an input that may be a iterable or not.
     """
     if isinstance(input, basetring):
     """ basetring is the only particular case as it is also an iterable"""
     do_the_stuff(input)
     else:
     try:
     iterable = (x for x in input)
     except TypeError:
     iterable = (input, )
     for i in iterable:
     do_the_stuff(i)
    
    

    Matthieu Gautier|irc:starmad