Golf - implementieren Sie ein einfaches Template-Schema.Golf - Expand Vorlagen in Textdatei
Expansionen sind:
- % KEY% -> VALUE
- %% ->%
Kommandozeilenargumente:
- ARG1: Wörterbuch-Datei, formatiert der
key=value
Stil wie in Beispiel - ARG2: templ aß Datei
Hier mein nicht ganz Golf Versuch (Python): 261 Zeichen.
import sys
dd = dict([ll.split("=",2) for ll in open(sys.argv[1],'r') if len(ll.split("=", 2)) == 2])
tt = "".join([ ll for ll in open(sys.argv[2],'r')])
sys.stdout.write("".join([(((s == "") and "%") or ((s in dd) and dd[s]) or s) for s in tt.split("%")]))
DICT
NAME=MyName
ODDS=100
TEMPLATE
I, %NAME% am %ODDS% %% sure that that this a waste of time.
RESULT
I, My Name am 100 % sure that this is a waste of time.
Ja, ich weiß, das ist ein defektes Template-System ist, "schnappt" für eine kürzere und besser Implementierung.
+1 Nizza, war ich über so etwas schreiben –