Last active
April 30, 2020 14:43
-
-
Save mcitron/445a2dc921fb23ecdff0 to your computer and use it in GitHub Desktop.
Viewer for arbitrary pickle files
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
#!/usr/bin/python | |
import pickle | |
from collections import defaultdict | |
from collections import OrderedDict | |
import sys | |
def checkDict(inputData): | |
return (type(inputData) == dict or type(inputData) == defaultdict\ | |
or type(inputData) == OrderedDict) | |
def checkList(inputData): | |
return type(inputData) == list | |
def recursivePrint(inputData,extraTuple = ()): | |
if checkDict(inputData): | |
for extraInfo,data in inputData.items(): | |
recursivePrint(data,(extraInfo,)+extraTuple) | |
elif checkList(inputData): | |
if all([not(checkList(x) or checkDict(x)) for x in inputData]): | |
print (" ".join([str(x) for x in extraTuple][::-1]),inputData) | |
else: | |
for data in inputData: | |
recursivePrint(data,extraTuple) | |
else: | |
print (" ".join([str(x) for x in extraTuple][::-1]),inputData) | |
def pickleViewer(inputFile): | |
inputData = pickle.load(open(inputFile,'rb')) | |
print ("Viewing pickle file {0} which contains data of type {1}".format(inputFile,type(inputData))) | |
recursivePrint(inputData) | |
if __name__ =="__main__": | |
assert len(sys.argv) == 2, "Usage: pickleViewer <input.pkl>" | |
pickleViewer(sys.argv[1]) |
ZanKa24, Remove the line
assert len(sys.argv) == 2, "Usage: pickleViewer <input.pkl>"
if you running it from the IDLE directly.
I developed this https://pickleviewer.com/ for this reason :)
I honestly just dumped this here for myself but it's now updated to fix bugs and work in Py3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got error below when I run your script. Please check it to me?
AssertionError: Usage: pickleViewer <input.pkl>