Bernd Hohmann wrote:
Ich hab hier gerade das Problem, dass ich ermitteln muss welcher Type einer Routine übergeben wurde. Denn manchmal ist das data.x/data.y und für andere Datentypen data.getTarget().x/data.getTarget().y
Leider wirft mir schon type(...) was unerwartetes aus:
match = region.find(pattern) print type(match) if type(match) is Match: print "Match" else: print "was anderes"
Ausgabe:
[error] TypeError (type(): 1st arg can't be coerced to String)
Was Andreas sagt... zumal es sich dabei wohl um eine Jython-spezifische Fehlermeldung handelt. Allgemein gesprochen kommst du möglicherweise ohne explizite Typprüfung aus: try: getTarget = data.getTarget except AttributeError: target = data else: target = getTarget() print target.x / target.y Alternativ: try: result = data.x / data.y except AttributeError: result = data.getTarget().x / data.getTarget().y print result