Code:
word="hello
hai"
fout=open("sample.txt","w");
fout.write(word);
Output:
hello
hai
But this:
word=b"hello
hai"
str_word=str(word) # stripping ' '(quotes) from byte
str_word=str_word[2:len(str_word)-1] # and storing just the org word
fout=open("sample.txt","w");
fout.write(str_word);
Outputs:
hello
hai
What is the problem in the code?
I am working on sending and receiving strings over a port in python. As only bytes can be sent and received I have the above problem. But why does it occur?
See Question&Answers more detail:os