- #1
chaoticflow
- 8
- 0
Hi,
I've been trying to write a simple binary file in Python 3 and have not yet been able to find a clear answer / solution online.
Could you please suggest a simple way to read / write binary files in Python 3?
My Code:
Any help is appreciated.
I've been trying to write a simple binary file in Python 3 and have not yet been able to find a clear answer / solution online.
Could you please suggest a simple way to read / write binary files in Python 3?
My Code:
Code:
# Create Binary File
def dec_base(k,b=2):
""" Default base is 2 """
num = ""
while k:
num +=str(k%b)
k = k//2
return int(num)
test_list = []
for i in range(10):
test_list.append(dec_base(i))
with open("test.bin", "wb") as f:
for i in test_list:
f.write(bin(int(i)))
Any help is appreciated.