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?
5 Answers
+ 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
+ 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
+ 6
Aha, if you want to write in binary mode, you should open the file with the 'wb' parameter, though.
0
@kuba ..thanks ..now to convert the bytes into a string and write the string to a new file?
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.