0

Python 3

I want to send a binary string over a socket. I am using

socket.send(b"Hello from {0}",client_id)

however I find the it is not properly substitution clientid.

what am I doing wrong? I do I accomplish this in a binary string

1 Answer 1

1

{0} is a placeholder for the str.format method, which you should be using, but bytes objects do not have a format method; instead, you can format it as a string first and then convert it to bytes with the encode method:

socket.send("Hello from {0}".format(client_id).encode())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.