URL: https://linuxfr.org/forums/programmation-python/posts/exceptions-imbriqu%C3%A9es Title: exceptions imbriquées Authors: norbs Date: 2010年06月11日T14:18:08+02:00 Tags: Score: 1 Hello, Dans un de mes programmes je cherche à transformer une chaîne en date. La chaîne peut avoir divers formats j'essaie donc tous les formats jusqu'à en trouver un qui marche mais pour ça j'ai une série d'exceptions imbriquées et je trouve que c'est très moche. Qu'est-ce que je pourrais faire de plus sympa en python ? £spaces£ £/spaces£try: £spaces£ £/spaces£d = time.strptime(s[:18], "%Y:%m:%d %H:%M:%S") £spaces£ £/spaces£except : £spaces£ £/spaces£try: £spaces£ £/spaces£d = time.strptime(s[:16], "%Y:%m:%d %H:%M") £spaces£ £/spaces£except : £spaces£ £/spaces£try: £spaces£ £/spaces£d = time.strptime(s[:16], "%Y:%m:%d:%H:%M") £spaces£ £/spaces£except: £spaces£ £/spaces£try: £spaces£ £/spaces£d = time.strptime(s[:16], "%d/%m/%Y %H:%M") #14/02/2009 18:16 £spaces£ £/spaces£except : £spaces£ £/spaces£try: £spaces£ £/spaces£d = time.strptime(s[:16],"%Y-%m-%d %H:%M") #2008年07月31日 20:33 £spaces£ £/spaces£except: £spaces£ £/spaces£try: £spaces£ £/spaces£d = time.strptime(s[:11], "%b %d %Y") #Nov 14 2007 £spaces£ £/spaces£except: £spaces£ £/spaces£try : £spaces£ £/spaces£d = time.strptime(s[:11],"%d %b %Y") #31 May 2009 12:4 £spaces£ £/spaces£except: £spaces£ £/spaces£d = None