+ 4

can you help me?

how can i make it work? https://code.sololearn.com/ciYu1mKhg3Pm/#py

14th May 2017, 1:17 PM
Hysji
8 odpowiedzi
+ 4
it isn't working
14th May 2017, 1:56 PM
Hysji
+ 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()
14th May 2017, 1:56 PM
Suyasa
Suyasa - avatar
+ 3
it seems it is working to me. what do you expect to happen and what do you get instead?
14th May 2017, 1:58 PM
ifl
ifl - avatar
+ 3
that it'll write : 'This has been written to a file' in binary
14th May 2017, 2:23 PM
Hysji
+ 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()
18th May 2017, 12:53 PM
Suyasa
Suyasa - avatar
+ 2
what do you want help with?
14th May 2017, 1:46 PM
ifl
ifl - avatar
18th May 2017, 12:10 PM
Hysji
+ 1
are you sure it's in binary (I think binary it's only 0s and 1s)
19th May 2017, 8:43 AM
Hysji