Q:

adding duplicated in a dictionary

I have this little code that write a 2 sys argv into a txt file.
First, everything for fine for writing in the file like I want but, the problem is I want to add the number of item if the user enter it and it is already in the list.
Example of input
up.py 1.txt apple 23

Example of the txt file 
apple : 20
orange : 28

expected output
apple : 43
orange : 28

The thing I tried is to make the file as a dictionary and then add the value chiffre in my code I don't understand why it doesn't work the way I entered it.
def maj(texte, item, nombre):
    with open(texte, "a") as ouvrir:
        mots_dict = {}
        lecture = ouvrir.readlines()
        for line in lecture:
            line = line.strip("\n")
            mot, chiffre = line.split(" : ")[0].strip(" "), int(line.split(" : ")[1].strip(" "))
            if mot == item:
                sum(mots_dict.values(chiffre))
                ouvrir.write("%s : %s" "\n" % (item, nombre))
                ouvrir.close()
                message = sys.exit()
                return message
            else:
                ouvrir.write("%s : %s" "\n" % (item, nombre))
                ouvrir.close()
                message = sys.exit()
                return message

def main():
    entree = sys.argv[1]
    item = sys.argv[2]
    nombre = sys.argv[3]
    choix = str(entree)
    texte = choix.strip("[']")
    maj(texte, item, nombre)

A:

I noticed that you initialize mots_dict to a blank dictionary, but you don't ever add anything to it.
So when you do sum(mots_dict.values()), it would return a 0.
If you do not want to change to JSON, and if you are not using the dictionary anywhere else later on, you can leave that part out and just do it like this here:
def maj(texte, item, nombre):
        with open(texte, "r") as f_in:
            lecture = f_in.readlines()
        with open(texte, "w") as ouvrir:
            for line in lecture:
               line = line.strip("\n")
               mot, chiffre = line.split(" : ")[0].strip(" "), int(line.split(" : ")[1].strip(" "))
                if mot == item:
                    ouvrir.write("%s : %s" "\n" % (item, str(chiffre + int(nombre))))
                else:
                    ouvrir.write("%s : %s" "\n" % (mot, chiffre))

Another thing I noticed is that when you write to ouvrir, you just write what value of nombre and item you got from the user input. If I understand your question, you want to keep the number unchanged from the input file if the item does not match what the user entered. Then you will want to write mot and chiffre to file, in the else block. Moreover, if you call system.exit() or return within the if block, it will not go through all the items in the original file.

