J'ai un gros problème pour mon projet isn, j'ai un fichier texte qui comporte des contacts a la suite des autre sous la forme:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
nom
telephone
date de naissance
mail
et je dois faire un programme qui est capable d'ajouter par exemple une 2eme adresse mail a un contact mais je n'arrive pas a le faire ; voila mon code:
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
#!/usr/bin/python3
#coding : utf-8
 
import time
 
 
def rechercheTel(fpath,s):
  tel = ""
  mail = ""
  anniv = ""
  f = open(fpath, 'r')
  i = 0
  while 1:
    line = f.readline()
    line = line.strip()
    i += 1
    if line:
      print("%d lignes lues"%i,end='\r')
      time.sleep(0.1)
      #print(len(line))
    else: 
        break
    if line==s:
       o = input("telephone")
       tel = f.readline()
       doc = list()
       doc.append(tel)
       doc.append(o)
       print(doc)
       break
  f.close()
  if len(tel)!=0:
    return(tel)
  else:
    return("Inconnu")
 
def ecrireTel(fpath,s):
  f = open(repertoire.txt, 'a')
  f.write(o)
  f.close()
 
 
s = input("Nom recherché?") 
print("Résultat de la recherche :"+rechercheTel('repertoire.txt',s))