1

I am new to python and am trying to write a python3 script that will edit the content of an existing text file and write it to a new text file. I currently have the following script which creates the new text file from the old one:

path = '/Users/uname/Desktop/soc-calc/TVs+Assigned+to+Local+Markets.txt'
tvfile = open(path,'r')
days = tvfile.read()

new_path = '/Users/uname/Desktop/soc-calc/tvs.txt'
new_days = open(new_path,'w')

new_days.write(days)
print(days)

tvfile.close()
new_days.close()

I have been searching and have been unable to find how I would make the script not only create a new document from the existing one, but remove all instances of the "-" character from the newly created text file.

Any help with what I would need to change or add to accomplish this would be helpful.

0

1 Answer 1

0

I found that I could adjust part of my code as follows to replace (remove) any "-" characters.

new_days.write(days.replace('-',''))

There were other recommendations as well, but this did what I needed and I can add other changes I need based on this

Sign up to request clarification or add additional context in comments.

Comments