+ 4
can you help me?
how can i make it work? https://code.sololearn.com/ciYu1mKhg3Pm/#py
8 Réponses
+ 4
it isn't working
+ 4
import struct
file = open("hh.txt", "w")
file.write("This has been written to a file")
file.close()
file=open("hh.txt","rb")
print(struct.unpack('31s',file.read(31)))
file.close()
+ 3
it seems it is working to me. what do you expect to happen and what do you get instead?
+ 3
that it'll write : 'This has been written to a file' in binary
+ 3
Is this the output you want?
import struct
import binascii
file = open("hh.txt", "w")
file.write("This has been written to a file")
file.close()
file=open("hh.txt","rb")
print(binascii.b2a_hex(struct.unpack('31s',file.read(31))[0]))
file.close()
or
file = open("hh.txt", "w")
file.write("This has been written to a file")
file.close()
file = open("hh.txt","rb")
data = file.read(31)
print(['0x%x' % x for x in data])
file.close()
+ 2
what do you want help with?
+ 1
are you sure it's in binary (I think binary it's only 0s and 1s)