1

I thought in python you can concat two strings, I might missing something in my little piece of code:

def create_set(feature, value):
  return b'{"type":"set","feature":'+feature+',"value":'+value+'}'

on = create_set("main.power", "on")
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
jagger85
  • 11
  • 1
  • 1
    You *can* concat two strings; as the error tells you, you can't concat `str` and `bytes`. Why are you using `b''`? – jonrsharpe Jan 11 '19 at 11:18
  • You absolutely don't need `b''` there. https://stackoverflow.com/questions/6269765/what-does-the-b-character-do-in-front-of-a-string-literal – Greg K. Jan 11 '19 at 11:23
  • you are right that was my problem, b is a sort of a code for the reciever – jagger85 Jan 11 '19 at 11:24
  • And it's way better to use string formatting - https://docs.python.org/3/library/string.html#format-string-syntax than concatenation. – buran Jan 11 '19 at 11:26

0 Answers0