Q:

When reading bytes from a file, reads it like a list

When I'm reading bytes from file using
open("file.txt", "rb"") python adds brackets in the beginning and end of the bytes, like list.
I've tried to manually cut the brackets using re.sub but because it is a list, I got an error code saying TypeError: expected string or bytes-like object since it's a list.
(The reason I used f.readlines(0) below instead of just normal file reading is because I store other variables on this file)
>>> foo = os.urandom("128")
>>> print(foo) 
b'\xb9\xfe\xeb\x03e\xe8\x8e\x0c\xc1\x05\xb1\xe8\xadB\x9d\xdf_-\xd2\x8c\x18\xe2\xb2\xc7\xf9I\x18\xa7(\xefe\xc9\xc4:\xb3\x93\n+\x7f\x8e\xd2\x82\xf0!\x9668\x01\xcdf\x0f\x15\xe6r\xec\x01\xb8\x7f\x8d\xa25\xd6yq\x1e#\xfb\x0eY\x0fE\x1a)V\xb2\xcb_\x89yH\xd9\xf9\xc7.\x12\x98\x16\xe4!k\xdfU>\xa2\xf0H\xcbT3.\xbd\xbdn\x8aU<\xeb\xf7\xca\xd6~\xf2R\xca\x0f\x8f\x9d\xce\xd8D\xa6f,H\xf8\xcc\xca\x1f' 
>>> f = open("t.text", "wb") 
>>> f.write(foo)
>>> f.close() 
>>> f = open("t.text", "rb") 
>>> bar = f.readlines(0)
>>> print(bar)
[b'\xb9\xfe\xeb\x03e\xe8\x8e\x0c\xc1\x05\xb1\xe8\xadB\x9d\xdf_-\xd2\x8c\x18\xe2\xb2\xc7\xf9I\x18\xa7(\xefe\xc9\xc4:\xb3\x93\n', b'+\x7f\x8e\xd2\x82\xf0!\x9668\x01\xcdf\x0f\x15\xe6r\xec\x01\xb8\x7f\x8d\xa25\xd6yq\x1e#\xfb\x0eY\x0fE\x1a)V\xb2\xcb_\x89yH\xd9\xf9\xc7.\x12\x98\x16\xe4!k\xdfU>\xa2\xf0H\xcbT3.\xbd\xbdn\x8aU<\xeb\xf7\xca\xd6~\xf2R\xca\x0f\x8f\x9d\xce\xd8D\xa6f,H\xf8\xcc\xca\x1f\xcc\x96\xaa\x9d\xc5\xebE\xc8\x0b\xe6G"\xb9\xf1T\x80']

How can I read it as bytes instead of list?
(I store other bytes on different lines, this on line 1 and another on line 2. I can't store them on different files).
EDIT: The solution is this: f.read(data_size).

A:

foo = f.readlines(0)

this is just reading all file lines as a list, with a size hint of zero (not very useful)
You want to read the first line just do:
foo = next(f)

note that if your data is binary, the notion of "line" won't help much, since if there's a linefeed char in your data, it will be seen as the end of a line.
Here it will happen, as the data you're writing is random. So consider storing the data as json or base64 encoded to make sure that a linefeed character doesn't get in the way (and it does, look at the full data you've read, it has 2 lines)
Or make note of the size of the data and use f.read(data_size). Knowning the size is the only way with binary streams.

