File size: 1,107 Bytes
6a46e44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pickle
import pprint
import argparse

def main():
    parser = argparse.ArgumentParser(description="Read and display contents of a pickle file.")
    parser.add_argument("file", help="Path to the .pkl file")
    args = parser.parse_args()

    print(f"Loading {args.file}...\n")
    try:
        with open(args.file, "rb") as f:
            data = pickle.load(f)
        
        print("Data Type:", type(data))
        if isinstance(data, list):
            print(f"Length/Number of items: {len(data)}")
        elif isinstance(data, dict):
            print(f"Keys: {list(data.keys())}")
        
        print("\n" + "="*50)
        print("Contents:")
        print("="*50)
        
        # Pretty print the data. If it's a massive list, we might want to just show the first few items.
        # But this will let you see exactly how it's structured.
        pprint.pprint(data, width=100, depth=4)

    except FileNotFoundError:
        print(f"Error: File not found -> {args.file}")
    except Exception as e:
        print(f"Error loading pickle: {e}")

if __name__ == "__main__":
    main()