Bonjour à tous, architecte en formation, débutant dans le language Python, j'ai un souci sur un script que j'essais de modifier à ma sauce.
Le lien du script https://github.com/Guy0m/text-genera.../generateur.py

Pour vous expliquer, je cherche à générer des phrase aléatoire avec des bases de données (listes de mots) : Verbe, nom communs etc

Voici ce que j'ai essayé de manipuler sans trouver la solutions (je précise que je n'ai aucune base en language python)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import sys
import random
 
class main:
 
        liste_determinants = list(open(r'determinants.txt', "rb").read().splitlines())
        liste_negatif = list(open(r'qualites.txt', "rb").read().splitlines())
        liste_positif = list(open(r'qualites.txt', "rb").read().splitlines())
        liste_sujet_verbe = list(open(r'verbes.txt', "rb").read().splitlines())
        liste_noms_communs = list(open(r'pieces.txt', "rb").read().splitlines())
        liste_resultat=[]
        choix = 'null'
        determinants = 'null,null'
        nom_commun = 'null,null'
        positif = 'null,null'
        negatif = 'null,null'
        classification = ['masculin', 'feminin'] #'neutre', 'pluriel', 'voyelle'
        tendance = 50; #tendance negative a 100, neutre a 50, positive a 0
 
 i=1
        while i<= 5: #nombre de phrases a generer
 
 
                if choix == 'null':
                        choix = random.choice(classification)
 
                while choix !=  determinants.split(',')[1]:
                        determinants=random.choice(liste_determinants)
 
                if tendance < random.randint(0,100):
                        while choix != positif.split(',')[1]:
                                positif=random.choice(liste_positif)
                                adjectif=positif
 
                else:
                        while choix !=  negatif.split(',')[1]:
                                negatif=random.choice(liste_negatif)
                                adjectif=negatif
 
                while choix !=  nom_commun.split(',')[1]:
                        nom_commun=random.choice(liste_noms_communs)
 
                phrase=random.choice(liste_sujet_verbe)+' '+determinants.split(',')[0]+' '+adjectif.split(',')[0]+' '+nom_commun.split(',')[0]
                liste_resultat.append(phrase)
                print (phrase)
                i=i+1
                choix = 'null'
                determinants = 'null,null'
                nom_commun = 'null,null'
                positif = 'null,null'
                negatif = 'null,null'
 
        resultat = open('resultat.txt', "w")
        resultat.write('\n'.join(liste_resultat))
        print('\nResultat : '+ resultat.name)

Pour le moment voici l'erreur :

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Input In [28], in <cell line: 2>()
6 choix = random.choice(classification)
8 while choix != determinants.split(',')[1]:
----> 9 determinants=random.choice(liste_determinants)
11 if tendance < random.randint(0,100):
12 while choix != positif.split(',')[1]:

NameError: name 'liste_determinants' is not defined

Mais je pense qu'elle va s'appliquer à toute les fcts de liste.
Mes fichiers textes sont bien entendu dans le bon dossier.
Je suis un peu perdu et c'est pour un projet d'architecture que j'essais de mettre en place (master2). merci d'avance à tous