2

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?
JJ Cauton
  • 109
  • 7
  • Does this answer your question? [How to convert string to byte array in Python](https://stackoverflow.com/questions/11624190/how-to-convert-string-to-byte-array-in-python) – itprorh66 Sep 30 '21 at 23:31
  • I don't understand what you mean by *'get "Hello" back into a string'*. "Hello" already is a string. – mkrieger1 Sep 30 '21 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 – mkrieger1 Sep 30 '21 at 23:48
  • What are you *actually* trying to do? I have the feeling this is an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) – mkrieger1 Sep 30 '21 at 23:50
  • Is your question now how you can split the bytearray at the `|` character? – mkrieger1 Oct 01 '21 at 01:01
  • So I am wondering if it is possible to turn a list into a byte array then turn it back into a list so that I can get the values? Sorry I edited my code to make it clearer. – JJ Cauton Oct 01 '21 at 01:07

0 Answers0