I'm trying to write a function that takes a filename as its argument and returns a string with all \n
characters replaced by the _
character.
This is what I did:
def replace_space(filename):
wordfile = open(filename)
text_str = wordfile.read()
wordfile.close()
text_str.replace("\n", "_")
replace_space("words.txt")
I also tried using " " instead of "\n":
text_str.replace(" ", "_")