Python - Remove the last character in a text file
Question: I m generating a file text as you can see below and i m trying to suppress the
last character "," of this file text after generating it but i cant...

    
    
    *Nset, nset
    0570, 0571, 0572, 0573, 0574, 0575, 0576, 0577, 0578, 0579, 0579
    0580, 0581, 0582, 0583, 0584, 0585, 0586, 0587, 0588, 0589, 0589
    0590, 0591, 
    

I have found on Stack this kind of code, but, it doesnt work...

    
    
    import sys
    with open(sys.argv[1]) as f, open('out.txt', 'w') as out:
         for line in f:
             out.write(line.split()[-1]+'\n')
    

\----EDIT LATER----

My code to generate the file text :

    
    
    fichier_write.write("*Nset,")
    fichier_write.write("\n")
    compt = 0
    for i in range(0,node_label.size):
        if Eleme_CI[i]!=0:
            fichier_write.write("%.4i, "%(Eleme_CI[i])),
            compt = compt + 1
        if compt == 10: 
            fichier_write.write("%.4i"%(Eleme_CI[i])),
            fichier_write.write("\n")
            compt = 0
    
    fichier_write.close()  
    


Answer: 
    import re
    # get text into a string \Z is the end of a string in regex
    with open('data') as f:
        text = f.read()
    
    text = re.sub(r'.\Z',r'',text)
    
    print(text)
    
    Money amount left 39.0
    *Nset, nset
    0570, 0571, 0572, 0573, 0574, 0575, 0576, 0577, 0578, 0579, 0579
    0580, 0581, 0582, 0583, 0584, 0585, 0586, 0587, 0588, 0589, 0589
    0590, 0591
    

