Skip to content

Instantly share code, notes, and snippets.

@mzaini30
Created March 3, 2017 13:30
Show Gist options
  • Save mzaini30/3e32bee0e950cfbf2fd1166ee69c1668 to your computer and use it in GitHub Desktop.
Save mzaini30/3e32bee0e950cfbf2fd1166ee69c1668 to your computer and use it in GitHub Desktop.
Mengubah spasi menjadi bentuk tabel markdown
import re
lokasi = "/sdcard/python/regex table/"
enter = "\n"
with open(lokasi+"/input.txt", "r") as file_input,\
open(lokasi+"/output.txt", "w") as file_output:
file_input = file_input.read()
file_input = re.sub(r"\t", r" | ", file_input)
file_input = file_input.splitlines()
hasil = file_input[0]
hasil += enter
hasil += "-|-"
hasil += enter
for n, x in enumerate(file_input):
if n != 0:
hasil+= x
hasil += enter
file_output.write(hasil)
print
print "done"
kucing hsvvdv hsgsgvdv satu
kucing hsvvdv hsgsgvdv dua
kucing hsvvdv hsgsgvdv tiga
kucing hsvvdv hsgsgvdv empat
kucing hsvvdv hsgsgvdv lima
kucing hsvvdv hsgsgvdv enam
kucing | hsvvdv | hsgsgvdv satu
-|-
kucing | hsvvdv | hsgsgvdv dua
kucing | hsvvdv | hsgsgvdv tiga
kucing | hsvvdv | hsgsgvdv empat
kucing | hsvvdv | hsgsgvdv lima
kucing | hsvvdv | hsgsgvdv enam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment