3

How would I convert a list of strings to a bytearray, then get the a certain value that is part of the list back into a string?

Here is my code:

test_list = ['Hello', 'World']
a = '|'.join(test_list)

test_array = bytearray(a.encode('utf-8'))
print(test_array)

# test("Hello")
print("Count of bytes:", len(byte_array))

# How would I get "Hello" back into a string?
6
  • Does this answer your question? How to convert string to byte array in Python Commented Sep 30, 2021 at 23:31
  • I don't understand what you mean by 'get "Hello" back into a string'. "Hello" already is a string. Commented Sep 30, 2021 at 23:47
  • 1
    What does the title have to do with the rest of the question? (1) there is no list here (2) you seem to know how to create a bytearray Commented Sep 30, 2021 at 23:48
  • What are you actually trying to do? I have the feeling this is an XY problem Commented Sep 30, 2021 at 23:50
  • Is your question now how you can split the bytearray at the | character? Commented Oct 1, 2021 at 1:01

0

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.