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
37
38
39
40
41
| import sys
args = sys.argv
def parse_args():
print(args)
if len(args) != 4:
print('参数有误')
print('命令行参数为 {-D/-E} { input_filename } { output_filename }')
return
if args[1] in ['-D', '--decode']:
decode(args[2], args[3])
return
if args[1] in ['-E', '--encode']:
encode(args[2], args[3])
return
def print_help():
...
def encode(input_name, dest_name):
input_file = open(input_name, 'rb')
out_file = open(dest_name, 'wb')
out_file.write(b'%PDF-1.4\n')
out_file.write(input_file.read())
input_file.close()
out_file.close()
def decode(input_name, dest_name):
input_file = open(input_name, 'rb')
out_file = open(dest_name, 'wb')
input_file.readline()
out_file.write(input_file.read())
input_file.close()
out_file.close()
parse_args()
|