user1463479
user1463479

Reputation: 63

python pickle dump non ascii

I would like to write something to a file (a result obtained from GNUPG) using Python in Linux so that I can read it in later and see whether the signature and data are still valid.

When I try to write the result to file in the following way (lines 16-18 from my code):

with open(“result.txt”, “w”) as my_file:
    pickle.dump(signed_data, my_file)
my_file.close()

I get the following problem:

python eg1.py 
    File "eg1.py", line 16
SyntaxError: Non-ASCII character '\xe2' in file eg1.py on line 16, but no encoding     declared; see http://www.python.org/peps/pep-0263.html for details

Although I could change to problematic values to something else and change them back when I read them back in later, I am wondering if it will be possible for me to simply save the file as I intend do without changing it?

Upvotes: 2

Views: 678

Answers (2)

guidot
guidot

Reputation: 5333

This error message has no relation to the binary stuff (signed_data) you want to write, but with the python source file. You gave no indication, what line number 16 is, but the typographic apostrophes in the "open"-line could be the reason.

Upvotes: 3

ely
ely

Reputation: 77424

If this is in Windows, then check into Unicode-related solutions, e.g. linked here.

Upvotes: 0

Related Questions