Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to save modification of a file in original file not a new one?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 274
    Answer it

    Dear all,

    I have a code to modify a file. This code make changes on my file and save it to a new file. But, I want to have changes(modifications) on my original file not a new one. I made attempts to change the code but it didn't work. How can I modify my code to save modification on my original file? My code is attached here.

    Thanks alot

    import csv
    
    with open('BTMA1.gro') as text_file, open('BTMA2.gro', 'w') as revised_file:
        reader = csv.reader(text_file, delimiter=' ')
        writer = csv.writer(revised_file, delimiter=' ', quoting=0)
    
        for idx, row in enumerate(reader, start=1):
            if idx >= 3:
                row.insert(1, row[1][0])
                row[2] = row[2][1:]
            writer.writerow(row)
    

     

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: