Answer the question
In order to leave comments, you need to log in
How to get bytes from python string?
How can I get a byte code from a string?
Example explaining my situation:
me_string = 'b"some bytes"'
me_string_utf = my_string.encode('utf8')
# b'b"some bytes"'
# но мне надо чтобы оно выводило b"some bytes"
Answer the question
In order to leave comments, you need to log in
my_string = 'b"some bytes"'
my_string = my_string[2:-1]
me_string_utf = my_string.encode('utf8')
print(me_string_utf)
import re
me_string = 'b"some bytes"' # нужно понимать что это - строка
result = re.match('^b\"(.*)\"$', me_string).group(1).encode()
print(result)
# b'some bytes'
print(type(result))
# <class 'bytes'>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question