-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuffman.py
36 lines (30 loc) · 854 Bytes
/
huffman.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from src.compress import compress
from src.decompress import decompress
def display_doc(*args):
"""
Display the documentation of the program.
"""
print("""For compress <my_file.txt>:
$ python huffman.py -c <my_file.txt>
For decompress <my_file.bin>:
$ python huffman.py -c <my_file.bin>""")
if __name__ == '__main__':
"""Huffman algorithm."""
try:
arg = sys.argv[1]
file_path = sys.argv[2]
except IndexError as e:
print("You need to give an argument and a filename!\n" % e)
print("See the documentation:")
display_doc()
else:
choices = {
'-c': compress,
'-d': decompress,
}
choices.get(arg, display_doc)(file_path)
finally:
print("Program finished.")