Created
February 28, 2017 14:11
-
-
Save Vages/0994872d1a4170e47400604a40c3dcfb to your computer and use it in GitHub Desktop.
Formats phone numbers
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
import os | |
filename = "mv17.csv" | |
phone_column = 2 | |
with open(os.path.join(".", filename), "r") as f: | |
new_lines = [] | |
for i, l in enumerate(f.readlines()): | |
if i == 0: | |
new_lines.append(l) | |
continue | |
elems = l.split(",") | |
phoneno = elems[phone_column].replace(" ", "") | |
if len(phoneno) == 8 and "+" not in phoneno: | |
phoneno = phoneno[:3] + " " + phoneno[3:5] + " " + phoneno[5:] | |
phoneno = "+47 " + phoneno | |
elems[phone_column] = phoneno | |
new_lines.append(",".join(elems)) | |
with open(os.path.join(".", "new_" + filename), "w") as g: | |
g.writelines(new_lines) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment