J'ai écrit ce code :
for i in range(0, 3):
for g in range(1, 4):
if i+1==g:
a = f'''r{g} = {list(df.iloc[i])}'''
with open('output.txt', 'w') as f:
f.write(f'''{a}''')
Voici le rendu que j'attends :
r1 = ['kane', 'grealish', 'sancho', 'sterling']
r2 = ['foden', 'mount', 'bellingham', 'reece']
r3 = ['trippier', 'stones', 'walker', 'coady']
Cependant, je ne reçois que r3 = ['trippier', 'stones', 'walker', 'coady']
Comment puis-je rectifier cela ?
Merci d'avance.
Remplacer
with open('output.txt', 'w') as f:
avec
with open('output.txt', 'a') as f:
## utilisez append lorsque vous ouvrez le fichier.
Cet article est collecté sur Internet, veuillez indiquer la source lors de la réimpression.
En cas d'infraction, veuillez [email protected] Supprimer.
laisse moi dire quelques mots