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()