Created
January 7, 2016 17:15
-
-
Save Xennis/dddd1b4ef10f69e9994f to your computer and use it in GitHub Desktop.
Split a texfiles
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 sys | |
def split_file(filename, num_max_lines=None): | |
num_lines = 0 | |
with open(filename) as f: | |
for line in f: | |
num_lines += 1 | |
sys.stdout.write(line) | |
if num_max_lines and num_lines >= num_max_lines: | |
break | |
if __name__ == '__main__': | |
argv = sys.argv[1:] | |
if len(argv) == 1: | |
split_file(argv[0]) | |
elif len(argv) == 2: | |
split_file(argv[0], int(argv[1])) | |
else: | |
print('Usage: split.py <FILENAME> <NUM-MAX-LINES>') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment