-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraducteur.py
68 lines (49 loc) · 2.03 KB
/
traducteur.py
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
57
58
59
60
61
62
63
64
65
66
67
import os
specials_keys = ["@exit","@help","@cats","@cat","@new","@ls","@input"]
dicoHelp = {"@exit":"To stop the program","@help":"To print help","@cats":"To load data from all files","@cat":" To load data from main file","@new":"To create or open a dictionnary file to input data","@ls":"To print all files availables to avoid an error of name for a field","@input":"To input data in the main file"}
def key_value(fichier,sep_k_v,sep_bloc_current_following):
global dico
with open(fichier,"r") as f:
for ligne in f :
key,value = ligne.split(sep_k_v)
dico[key]=value
def inputDict(fichier,sep_k_v,sep_bloc_current_following):
with open(fichier,"a") as f:
key = ""
while key!="exit":
key = input("<<(key) ")
if key!="exit":
value = input(" <<(value) ")
f.write(key+sep_k_v+value+sep_bloc_current_following)
fichiers = [file for file in os.listdir('.') if ("vocabulaire" in file and "csv" in file)]
fichier = "vocabulaire.csv"
key = ""
dico = dict()
while key != "@exit":
key = input(">> ")
if key == "help" or key == "exit" or key=="@help":
print("Maybe you mistook")
print("If you want to find details, you can use these commands :")
for specKey in specials_keys:
print(f"Input {specKey} :")
print(dicoHelp[specKey])
print("")
print(":::::\n")
if key == "@ls":
print(fichiers)
if key == "@cat":
key_value(fichier,";","\n")
if key == "@cats":
for f in fichiers:
key_value(f,";","\n")
if key == "@new":
field=input("@ which (new) field ?")
f = "vocabulaire"+"_"+field+".csv"
if f not in fichiers:
fichiers.append(f)
inputDict(f,";","\n")
if key == "@input":
inputDict(fichier,";","\n")
for k in dico.keys():
if key in k:
print(k+" --> " + dico[k])