0
with s:
    message = pyautogui.prompt('enter data', 'Send Data')
    s.sendall(**b'variable goes here'**)
    data = s.recv(1024)

In line 3, I need to put a variable inside of the parentheses, but keep the bytes prefix, or an equivalent, something like this:

s.sendall(b'somerandomtext{variable}')

How can I do this?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • Voting to close as duplicate of [Best way to convert string to bytes in Python 3?](https://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3) – mkrieger1 Jul 05 '20 at 19:51

1 Answers1

0

I think you can do it with following step:

var = "dynamic"

msg = "this is a {} message".format(var)

bytMsg = msg.encode('utf-8')

s.sendall(bytMsg)
Aminul
  • 1,427
  • 2
  • 8
  • 16