Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
bytes f-string ?
#2
The brace expands to the str representation of the object. And the str representation of foo is b'hello'. So that's what gets inserted.

You could try to convert your bytestring before inserting, or you could assemble your bytes together directly.

foo = b'hello'
fs = f'{foo.decode()}bar'
bfs = fs.encode()
print(bfs)

foo = b'hello'
fs = foo + 'bar'.encode() # Not using f-strings
print(fs)
Reply


Messages In This Thread
bytes f-string ? - by Skaperen - Jun-08-2021, 10:43 PM
RE: bytes f-string ? - by bowlofred - Jun-09-2021, 01:40 AM
RE: bytes f-string ? - by Gribouillis - Jun-09-2021, 06:47 AM
RE: bytes f-string ? - by Skaperen - Jun-09-2021, 06:27 PM
RE: bytes f-string ? - by DeaD_EyE - Jun-10-2021, 06:07 AM
RE: bytes f-string ? - by Gribouillis - Jun-10-2021, 10:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 7 7,100 Aug-03-2023, 06:00 PM
Last Post: Gribouillis
  TypeError: int() argument must be a string, a bytes-like object or a number, not 'Non Anldra12 2 5,266 May-02-2021, 03:45 PM
Last Post: Anldra12
  how to do a bytes f-string? Skaperen 4 11,249 Jul-16-2020, 11:25 PM
Last Post: Skaperen
  Why, TypeError: expected string or bytes-like object ? JohnnyCoffee 3 18,672 May-08-2020, 04:26 AM
Last Post: bowlofred
  printing a bytes string Skaperen 2 2,403 Jul-21-2019, 03:42 AM
Last Post: Skaperen
  replace bytes with other byte or bytes BigOldArt 1 10,700 Feb-02-2019, 11:00 PM
Last Post: snippsat
  portion of the bytes to string ricardons 1 2,643 Mar-02-2018, 12:00 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020