CentauriAurelius
CentauriAurelius

Reputation: 504

Editing and resaving files using Python

I would like to know how to use Python to perform simple edits/augmentations to a set of files within a folder and then save those edited files (either overwrite or with new names).

For example, I have a set of .csv files that I want all only the first column of data with all special characters removed (e.g. periods and apostrophes). I don't want to have to manually do this for every file so I would like to have an automated Python script that can do this.

Upvotes: 2

Views: 81

Answers (1)

KJai
KJai

Reputation: 38

here is a basic outline of the script:

import glob

for fname in glob.glob('data_folder/*.csv'):
    with open(fname,'r') as f:
       # code to read data from the file and manipulate the data
       with open('new_file_name','w') as f_new:
           # code to write data to the new file

Upvotes: 2

Related Questions