ich habe ein kleines Problem und bin absolut ratlos.
Mein Projekt beinhaltet (unter anderem) folgendes:
Sprachtemplates (string) mit Variablen:
Code: Alles auswählen
__INVALID_VALUE__ = "Invalid value: <VARIABLE> = '<VALUE>'"
Code: Alles auswählen
def parse_template(self, text, variables, values):
""" Replaces the intern variables of VScan (like: <HOST>) with
values. Supposed to parse the language object.
Parameters:
text - (string) The string which contains the
variables.
variables - (array) The variables without patterns.
values - (array) Elements of this list will be
replaced with variables[] in order.
Example:
>>> print self.parse_template("The <OBJECT> is <COLOR>.", ['OBJECT', 'COLOR'], ['devil', 'red'])
The devil is red.
"""
if len(variables) != len(values):
self.err(self.language.__NOT_SAME_SIZE__)
for i in range(0, len(variables)):
pattern = self.config.pattern % (variables[i])
if pattern in text and values[i] != None:
text = replace(text, pattern, str(values[i]))
return text
Code: Alles auswählen
def err(self, text):
if self.config.debug_mode == 1: print text
Also: Diese 3 Dinge zusammen wollen einfach nicht harmonieren. Er gibt den geparsten Text zwar aus, hängt aber immer ein "None" dahinter!
Wenn ich print text zu print "'" + text + "'" ändern würde, käme folgendes heraus:text
None
Ich bin absolut verzweifelt und hoffe dass mir hier jemand helfen kann.'text'
None
Edit: Ach so, vielleicht noch ein Aufruf:
Code: Alles auswählen
self.err(self.parse_template(self.language.__INVALID_VALUE__, ['VARIABLE', 'VALUE'], ['protocol', self.config.protocol]))
Invalid value: protocol = 'tcdp'
None