I am newbie to programming, and have been studying python in my spare time for the past few months. I decided I was going to try and create a little script that converts Ame
The print
statement adds a newline of its own, but your lines already have their own newlines. You can either strip the newline from your new_line
, or use the lower-level
output.write(new_line)
instead (which writes exactly what you pass to it).
For your second question, I think we need an actual example. replace()
should indeed replace all occurrences.
>>> "abc abc abcd ab".replace("abc", "def")
'def def defd ab'
I'm not sure what your third question is asking. If you want to replace the output file, do
output = open('output_test_file.txt', 'w')
'w'
means you're opening the file for writing.