TypeError: an integer is required (got type str)

nailad - Modifié le 25 avril 2020 à 20:53
Whismeril Messages postés 19027 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 24 avril 2024 - 26 avril 2020 à 17:18
Bonjour,
je veux répondre à cette question "Write a Python program to find all Dates in a text (Both French Format and English Format )" mon code est le suivant:

def date_en_fr(text):
    for match in re.findall(r"\d{2}/\d{2}/\d{4}", text):
        print(match)
        if date(match).isoformat() == '%m/%d/%Y':
            print("Date is {}, in English format".format(match))
        elif date(match).isoformat() ==  '%d/%m/%Y':
            print("Date is {}, in French format".format(match))
        else:
            print("Date don't verify the both format")

        
print(date_en_fr("I have a meeting on 12/29/2019 in New York, an other on 02/14/2019 and the last on 29/12/2018 in Paris."))


est ce que pourriez-vous m'aider à le corriger?
A voir également:

3 réponses

Whismeril Messages postés 19027 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 24 avril 2024 656
Modifié le 26 avril 2020 à 15:56
Bonjour

Merci à @karamel d'avoir rendu ton code exploitable.
Voir ce petit tuto pour tes prochains posts https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code

Je ne code pas en Python, juste pour les questions simples sur le forum.

J'ai donc copié collé ton code dans un compilateur en ligne, ce compilateur me dit qu'à la ligne 2 la variable "re" n'existe pas.
Je pense que ton propre compilateur a du te signaler la même chose.

Peut-être devrais tu commencer par là.

1
Rejoignez-nous