txlyre 6 bulan lalu
induk
melakukan
a6493f8a4c
1 mengubah file dengan 3 tambahan dan 2 penghapusan
  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)