Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • Exactly what I was going to post, pretty much. +1 when you fix the problem with write not having a self argument. Also, it'd be better design to have the file that you're going to write to passed in. Hell, it might also be better design to have stdout passed in. Commented Mar 5, 2009 at 21:23
  • @Devin, yeah this was quick and dirty, I'll make some notes for possible early improvements. Commented Mar 5, 2009 at 21:25
  • 7
    I selected this answer too soon. It works great for "print", but not so much for external command output. Commented Mar 5, 2009 at 21:53
  • 3
    The Logger class should also define a flush() method such as "def flush(): self.terminal.flush(); self.log.flush()" Commented Mar 26, 2010 at 7:57
  • 6
    You say The print statement will call the write() method of any object you assign to sys.stdout. And what about other functions sending data to stdout not using print. For instance, if I create a process using subprocess.call its output goes to the console but not to log.dat file...is there a way to fix that? Commented Jul 23, 2015 at 12:41