Created
October 10, 2014 09:47
-
-
Save evilkost/2ec94af60a829f04f165 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
class Writer(object): | |
def __init__(self, base_dir): | |
self.base_dir = base_dir | |
self.pool = {} | |
def _get_fh(self, name): | |
if name not in self.pool: | |
self.pool[name] = open(os.path.join(self.base_dir, name), "w") | |
return self.pool[name] | |
def write(self, name, data): | |
fh = self._get_fh(name) | |
fh.write(data) | |
def clost(self): | |
for _, fh in self.pool: | |
fh.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment