Apparently, the following is the valid syntax:
my_string = b\'The string\'
I would like to know:
b
Here's an example where the absence of b
would throw a TypeError
exception in Python 3.x
>>> f=open("new", "wb")
>>> f.write("Hello Python!")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' does not support the buffer interface
Adding a b
prefix would fix the problem.
The answer to the question is that, it does:
data.encode()
and in order to decode it(remove the b
, because sometimes you don't need it)
use:
data.decode())
From server side, if we send any response, it will be sent in the form of byte type, so it will appear in the client as b'Response from server'
In order get rid of b'....'
simply use below code:
Server file:
stri="Response from server"
c.send(stri.encode())
Client file:
print(s.recv(1024).decode())
then it will print Response from server