Browse Source

first comit

cromatiste 3 years ago
commit
750875458d
2 changed files with 14 additions and 0 deletions
  1. 0 0
      README.md
  2. 14 0
      splittxt.py

+ 0 - 0
README.md


+ 14 - 0
splittxt.py

@@ -0,0 +1,14 @@
+import os
+
+lines_per_file = 300
+smallfile = None
+with open('/home/marco/Py/really_big_file.txt') as bigfile:
+    for lineno, line in enumerate(bigfile):
+        if lineno % lines_per_file == 0:
+            if smallfile:
+                smallfile.close()
+            small_filename = 'small_file_{}.txt'.format(lineno + lines_per_file)
+            smallfile = open(small_filename, "w")
+        smallfile.write(line)
+    if smallfile:
+        smallfile.close()