Saturday, 7 September 2013

python3, writing the letter A to a file in binary mode

python3, writing the letter A to a file in binary mode

I have what is probably a very simple question. Despite being simple, I
haven't been able to find a duplicate question. Apologies, if this is a
re-post.
In python 3 these statements are True:
ord('A') == 65
chr(65) == 'A'
bin(65) == '0b1000001'
hex(65) == '0x41'
int(b'1000001',2) == 65
Given the integer i = 65, how do I in Python 3 open a file in binary mode
and write the byte 01000001 to file?
Thank you.

No comments:

Post a Comment