0

Here's my code:

list = ["example"]
def speichern(charts):
    f = open("test.txt", "wb")
    pickle.dump(list, f, )
    f.close()

It works, but the content of test.txt is:

€]q ]q(X   exampleqX    qea

How do I fix this?

Pika Supports Ukraine
  • 3,612
  • 10
  • 26
  • 42
  • 1
    There's nothing to "fix" here. What did you *expect* to happen? – Aran-Fey Mar 14 '19 at 13:28
  • Not sure what you're trying to do here, but you're writing binary pickle content to that file. You need to unpickle it when you load it again. If you want it to be human readable, you want to json.dump() it, not pickle it. – Atlas Mar 14 '19 at 13:29
  • not sure where is the problem , please read about `pickle.dump` and you will see it is expected behavior . see : https://docs.python.org/3/library/pickle.html – ddor254 Mar 14 '19 at 13:31
  • ty guys :D someone can say me whats advantage and disadvantage for using pickle dump or json dump? – Robin Müller Mar 14 '19 at 13:40
  • https://stackoverflow.com/questions/2259270/pickle-or-json – snakecharmerb Mar 14 '19 at 13:49

0 Answers0