-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpickle
executable file
·40 lines (38 loc) · 963 Bytes
/
pickle
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
#!/usr/bin/env python
import pickle, sys, os
import numpy as np
import marshal as m
thefile = sys.argv[1]
if not os.path.exists(thefile):
print "Error: file", thefile, "does not exist."
elif (thefile[-4:] == ".pkl"):
a = pickle.load(open(thefile, "rb"))
if (type(a) == list):
for i in range(len(a)):
print a[i]
try: print "dimensions", len(a), "x", len(a[0])
except: print len(a)
elif (type(a) == dict):
for key, value in a.iteritems():
print key, ":", value
else:
print a
try: print "dimensions", len(a), "x", len(a[0])
except: print "length", len(a)
elif (thefile[-4:] == ".npz"):
a = np.load(thefile)
print sys.argv
if (len(sys.argv) == 2):
for f, x in a.items():
print(f)
else:
b = a[sys.argv[2]]
print b
print len(b)
elif (thefile[-4:] == ".mar"):
a = m.load(open(thefile, "rb"))
print a
if (len(a) > 1):
for i in range(len(a)):
print a[i]
print len(a)