txlyre 6 月之前
父節點
當前提交
a6493f8a4c
共有 1 個文件被更改,包括 3 次插入2 次删除
  1. 3 2
      markov.py

+ 3 - 2
markov.py

@@ -59,8 +59,9 @@ class Markov:
                 self.corpus = json.load(f)
 
     def save(self):
-        with open(config.MARKOV_CHAIN_PATH, "w") as f:
-            f.write(self.chain.to_json())
+        if self.chain:
+            with open(config.MARKOV_CHAIN_PATH, "w") as f:
+                f.write(self.chain.to_json())
 
         with open(config.MARKOV_CORPUS_PATH, "w") as f:
             json.dump(self.corpus, f)