Created
November 7, 2020 12:47
-
-
Save nonchris/c05c869382b7478d626d1b89e32fef14 to your computer and use it in GitHub Desktop.
symbol replacer for file content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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