Generalize running scripts

This commit is contained in:
2021-05-10 22:12:15 +02:00
parent 9358971583
commit 0cfd95ad59
5 changed files with 78 additions and 10 deletions
+27 -7
View File
@@ -1,5 +1,10 @@
from sys import argv
from pathlib import Path
try:
from tabulate import tabulate
except:
print('Couldn\'t find tabulate. Do you have it installed?')
def parseExpressionList(inputData):
return [e.strip() for e in inputData.split(',')]
@@ -77,12 +82,27 @@ def latexify(exps, truthtable):
""".format(
'|'.join('e' if e else 'c' for e,_ in latex_expressions),
' & '.join(f'${exp}$' for _,exp in latex_expressions),
'\n'.join(' ' + ' & '.join('\\T' if b else '\\F' for b in line) for line in truthtable)
'\n'.join(' ' + ' & '.join('\\T' if b else '\\F' for b in line) + ' \\\\' for line in truthtable)
)
def printTruthtable(exps, truthtable):
stringTable = [ ['\033[32mT\033[0m ' if b else '\033[31mF\033[0m' for b in line] for line in truthtable]
print(tabulate(stringTable, headers=exps))
try:
print(tabulate(stringTable, headers=exps))
except:
pass
def processFileContent(raw, template):
exps = parseExpressionList(raw)
truthtable = generateTruthTable(exps)
printTruthtable(exps, generateTruthTable(exps))
content = latexify(exps, truthtable)
return template.replace('%CONTENT', content)
if __name__ == '__main__':
filename = argv[1]
@@ -91,11 +111,11 @@ if __name__ == '__main__':
exps = parseExpressionList(file.read())
truthtable = generateTruthTable(exps)
try:
from tabulate import tabulate
printTruthtable(exps, generateTruthTable(exps))
except:
print('Couldn\'t find tabulate. Do you have it installed?')
# try:
from tabulate import tabulate
printTruthtable(exps, generateTruthTable(exps))
# except e:
# print(e)
content = latexify(exps, truthtable)