[Python] read text file written in pickle format

Discussão em 'Python' iniciado por Stack, Maio 25, 2025.

  1. Stack

    Stack Membro Participativo

    we have given this file : http://www.sociology-hacks.org/wp-content/uploads/2014/01/graph.txt

    i tried to read this file using this code :

    import pickle
    import copyreg
    import networkx as nx
    with open("graph.txt", 'rb') as file:
    response =file.read()
    response


    result is this :

    b"ccopy_reg\r\n_reconstructor\r\np0\r\n(cnetworkx.classes.graph\r\nGraph\r\np1\r\nc__builtin__\r\nobject\r\np2\r\nNtp3\r\nRp4\r\n(dp5\r\nS'node'\r\np6\r\n(dp7\r\nS'PORTUGAL'\r\np8\r\n(dp9\r\nsS'LUXEMBOURG'\r\np10\r\n(dp11\r\nsS'COTE IVOIRE'\r\np12\r\n(dp13\r\nsS'COSTA


    RICA'\r\np14\r\n(dp15\r\nsS'ETHIOPIA'\r\np16\r\n(dp17\r\nsS'SWEDEN'\r\np18\r\n(dp19\r\nsS'PERU'\r\np20\r\n(dp21\r\nsS'NORWAY'\r\np22\r\n(dp23\r\nsS'IRAN'\r\np24\r\n(dp25\r\nsS'DENMARK'\r\np26\r\n(dp27\r\nsS'NEPAL'\r\np28\r\n(dp29\r\nsS'ZIMBABWE'\r\np30\r\n(dp31\r\nsS'ECUADOR'\r\np32\r\n(dp33\r\nsS'AUSTRALIA'\r\np34\r\n(dp35\r\nsS'ENGLAND'\r\np36\r\n(dp37\r\nsS'TANZANIA'\r\np38\r\n(dp39\r\nsS'SCOTLAND'\r\np40\r\n(dp41\r\nsS'FRANCE'\r\np42\r\n(dp43\r\nsS'SRI LANKA'\r\np44\r\n(dp45\r\nsS'NETHERLANDS'\r\np46\r\n(dp47\r\nsS'SOUTH

    how to read this content? i have tried this code :

    import pickle
    import copyreg
    import networkx as nx
    with open("graph.txt", 'rb') as file:
    response = pickle.load(file)


    error is this :

    4 with open("graph.txt", 'rb') as file:
    ----> 5 response = pickle.load(file)

    ModuleNotFoundError: No module named 'copy_reg\r'


    how to solve this issue?

    Continue reading...

Compartilhe esta Página