Change the way to convert .csv into .py files

This commit is contained in:
Shadow15510 2021-08-20 16:35:17 +02:00
parent e625730293
commit a0e48ea23c
1 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,8 @@
def to_string(csv_filename, output_filename="world"):
#! /usr/bin/env python3
from sys import argv
def convert_to_string(csv_filename):
char_list = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ "
with open(csv_filename, "r") as file:
@ -10,5 +14,7 @@ def to_string(csv_filename, output_filename="world"):
output += char_list[char_id]
output += "\n"
with open(f"{output_filename}.py", "w") as file:
file.write(f"{output_filename}_map = r\"\"\"\n{output}\n\"\"\"")
with open(f"{csv_filename.split(".")[0]}.py", "w") as file:
file.write(f"{output_filename}_map = r\"\"\"\n{output}\n\"\"\"")
convert_to_string(*argv[1:])