from string import strip def w2f(self,s,*args,**kws): """ Zope debugging tool. Use from anywhere in Zope as an External Method, to print things to a file. Very useful in Python Scripts or DTML/ZPT where you do RESPONSE.redirect for example. Call in Python Script like this: context.w2f("this part is being used") or context.w2f("this part is being used",pagetitle=context.title_or_id()) or context.w2f("this part is being used",reset=1) to make this thing reset the debugger file. or context.w2f("this part is being used",stdout="Print to stdout this") """ printstmt = "Using Write2File module in %s"% self.title_or_id() if kws.has_key('stdout'): printstmt = kws['stdout'] print printstmt fileplace='c:\\peter\\file.txt' if kws.has_key('reset'): reset=1 else: reset=0 s=str(s) for arg in args: s=s+'\n%s'%arg for k,v in kws.items(): s=s+'\n%s = %s'%(k,v) s=strip(s) content="" if not reset: try: r=open(fileplace,'r') content=r.read() r.close() del r except:pass f=open(fileplace,'w') f.write('From %s:\n%s\n\n'%(self.title_or_id(),s)) f.write(content+'\n') f.close() del f return "done"