Skip to content

Instantly share code, notes, and snippets.

@nonchris
Created November 7, 2020 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nonchris/c05c869382b7478d626d1b89e32fef14 to your computer and use it in GitHub Desktop.
Save nonchris/c05c869382b7478d626d1b89e32fef14 to your computer and use it in GitHub Desktop.
symbol replacer for file content
def conv(file: str, new="converted-file.txt", symbol=",", rep=".") -> str:
"""
Needs: filename
Optional: filename, symbol to replace, symbol to replace with
- reads data, replaces a symbol with an other symbol of choice
- writes new data in file and returns filename
"""
with open(file, "r") as f: #open file
read = f.read() #read content
repl = read.replace(symbol, rep) #replace symbol
g = open(new, "w") #open new file to write result
g.write(repl) #writing
g.close()
return new #returning filename
#file = conv('data_with_comma.txt', new='better_data.txt')
#arrayy = np.loadtxt(file, skiprows=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment