I just started with Python and want to find the binary code for any given character in a text file. The problem I encountered is when it prints the binary there is a "b" in the binary.
file = open("textfile.txt","w")
file.write("Hello World ")
file.write("This our new text file")
file.write("and this is another line. ")
file.write("Why? Because we can.")
file.close()
with open("textfile.txt") as file:
data=file.readline()
data_vector = list(data)
binary_data_vector = map(bin, bytearray(data_vector))
print(binary_data_vector)
This is the output I am currently getting:
['0b1001000', '0b1100101', '0b1101100', '0b1101100', '0b1101111', '0b100000', '0b1010111', '0b1101111', '0b1110010', '0b1101100', '0b1100100', '0b100000', '0b1010100', '0b1101000', '0b1101001', '0b1110011', '0b100000', '0b1101111', '0b1110101', '0b1110010', '0b100000', '0b1101110', '0b1100101', '0b1110111', '0b100000', '0b1110100', '0b1100101', '0b1111000', '0b1110100', '0b100000', '0b1100110', '0b1101001', '0b1101100', '0b1100101', '0b1100001', '0b1101110', '0b1100100', '0b100000', '0b1110100', '0b1101000', '0b1101001', '0b1110011', '0b100000', '0b1101001', '0b1110011', '0b100000', '0b1100001', '0b1101110', '0b1101111', '0b1110100', '0b1101000', '0b1100101', '0b1110010', '0b100000', '0b1101100', '0b1101001', '0b1101110', '0b1100101', '0b101110', '0b100000', '0b1010111', '0b1101000', '0b1111001', '0b111111', '0b100000', '0b1000010', '0b1100101', '0b1100011', '0b1100001', '0b1110101', '0b1110011', '0b1100101', '0b100000', '0b1110111', '0b1100101', '0b100000', '0b1100011', '0b1100001', '0b1101110', '0b101110']
So my question is how can I get rid of "b" so it prints only 8 bits for each character. And if you know why this happens, please explain!.