# HG changeset patch # User Jeff Hammel # Date 1606243640 28800 # Node ID d2060c9bdb31f43bda5d35d5888ce4c149e56f16 # Parent 50b319ad87b82fc5bf2a9096926c373cb30ba18b py3 diff -r 50b319ad87b8 -r d2060c9bdb31 wordstream/api.py --- a/wordstream/api.py Tue Nov 24 10:44:13 2020 -0800 +++ b/wordstream/api.py Tue Nov 24 10:47:20 2020 -0800 @@ -29,30 +29,28 @@ with urlopen(arg) as response: text = response.read() else: - text = file(arg).read() + text = open(arg).read() self.feed_stream(text) def scramble(self): for i in self: shuffle(self[i]) - def save(self, filename): + def save(self, f): named = False - if isinstance(f, basestring): + if isinstance(f, str): named = True - f = file(f) + f = open(f) for key in sorted(self.keys()): - print >> f, "%s %s" % (key, ' '.join(self[key])) + f.write("%s %s\n" % (key, ' '.join(self[key]))) if named: f.close() - + def load(self, f): - if isinstance(f, basestring): - f = file(f) - + if isinstance(f, str): + f = open(f) @classmethod def restore(cls, filename): corpus = cls() corpus.load(filename) -