0

There is a text file in my directory.I want to convert the text in the file into bytes.How can i do it in Python 3?

25th Jun 2017, 3:44 AM
suryapoojary
suryapoojary - avatar
5 Respuestas
+ 6
Try the code below and check if this is the output you want. If so, just print it out like this or write it to another file, if you wanted to convert. https://code.sololearn.com/chy4pff7J132/?ref=app
25th Jun 2017, 5:38 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
I think you do b'your textfile stuff here' or something. it's been a while since I've had to do it so that may be somewhat wrong
25th Jun 2017, 6:17 AM
Ahri Fox
Ahri Fox - avatar
+ 6
Aha, if you want to write in binary mode, you should open the file with the 'wb' parameter, though.
25th Jun 2017, 6:24 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
@kuba ..thanks ..now to convert the bytes into a string and write the string to a new file?
25th Jun 2017, 6:20 AM
suryapoojary
suryapoojary - avatar
0
@kuba,if I write it in binary..how do I convert the binary format into a string format and write that string to a new file.
25th Jun 2017, 6:25 AM
suryapoojary
suryapoojary - avatar