Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Incomplete output of pickle.load in Python

I am making a game and I want to export and import the terrain. It’s a 100×100 grid (2d list of numbers). At first, I export it to a save.dat file using pickle.dump( ) and then i import it using pickle.load( ).

But in console I see something like this:

Data: [[1, 3, 4, 4, 11, 5, 8, 13, 8, 10, 12, 7, 6, 6, 9, 13, 7, 5, 1, 2, 12, 7, 6, 9, 13, 7, 5, 0, 1, 12, 8, 10, 12, 8, 13, 0, 7, 9, 4, 11, 6, 9, 4, 4, 13, 7, 9, 4, 13, 8, 4, 4, 13, 1, 3, 4, 10, 12, 0, 0, 8, 10, 12, 1, 3, 13, 0, 1, 2, 3, 13, 1, 3, 10, 2, 2, 3, 4, 4, 10, 3, 11, 9, 13, 7, 6, 5, 7, 6, 6, 5, 7, 5, 7, 9, 13, 8, 11, 6, 5], [

...

], [12, 8, 11, 9, 4, 10, 12, 1, 12, 1, 2, 12, 1, 3, 4, 1 2, 12, 0, 8, 4, 4, 4, 13, 0, 7, 9, 4, 13, 8, 4, 11, 6, 9, 13, 7, 9, 10, 2], [7, 9,

It ends uncomplete. Here is my code:
(g is the grid)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    def export_data(self):
        with open("save.dat", "wb") as fout:
            pickle.dump(self.g, fout)
        print("Export successful!")

    def import_data(self):
        with open("save.dat", "rb") as fin:
            a = pickle.load(fin)
            print("Import successful!")
            print("Data:", a)

I think it may be caused by limited length of output but I don’t know, how to make it better. Thanks for answer.

>Solution :

It’s the terminal that cuts off most of the lines.

But the whole 100×100 array is stored in the variable a. If you want to double check, you can check its length

print(len(a))

If you want your terminal to show all the lines, you can configure your code editor.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading