import arcgisscripting import sys class GPPrint(object): """ Use enable or disable print please """ def __init__(self, gp, is_stderr = False): """ Initializer """ self.gp = gp self.is_stderr = is_stderr def __del__(self): self.gp = None def write(self, msg): if msg == '\n': return if self.gp: if not self.is_stderr: self.gp.addmessage(msg) else: self.gp.adderror(msg) def flush(self): pass def writelines(self, msg): self.write('\n'.join(msg)) def close(self): pass gp = arcgisscripting.create() sys.stderr = GPPrint(gp, True) sys.stdout = GPPrint(gp, False) print "Hi" print "Hello normally this would not work but i am " # Now lets say we want to restore the streams... sys.stderr = sys.__stderr__ sys.stdout = sys.__stdout__
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.