Q:

How to convert signed string to its Binary equivalent in Python?

I am using the itertool function to enter value to a list. The itertool function is taking the value as a str, not as an int. After that, I need to convert the values from the list to its Binary equivalent. The problem arises when I need to convert a negative value e.g. -5. My code is taking the "-" as a str, but I need it to consider it as a negative sign before the following numerical value.Does the concept of unsigned integer come into play?
My code is-
L3= list(itertools.repeat("-1",5))

file= open(filename, 'w')

L3_1=[ ]

for item in L3:

       x3=bytes(item,"ascii")
       L3_1.append(' '.join(["{0:b}".format(x).zfill(8) for x in x3]))

for item in L3_1:

       file.write("%s\n" % item)

file.close()

A:

It's not entirely clear what your problem is and what you want to achieve, so please correct me if I make wrong assumptions.
Anyways, converting integers to binary representation is easily done using bin. For example, bin(5) gives you '0b101'. Now, bin(-5) gives you '-0b101' - which is not what you expect when being used to binary from other languages, e.g. C.
The "problem" is that integers in python are not fixed size. There's no int16, int32, uint8 and such. Python will just add bits as it needs to. That means a negative number cannot be represented by its complement - 0b11111011 is not -5 as for int8, but 251. Since binaries are potentially infinite, there's no fixed position to place a sign bit. Thus, python has to add the explicit unary -. This is different from interpreting -5 as the strings "-" and "5".
If you want to get the binary representation for negative, fixed size integers, I think you have to do it by yourself. A function that does this could look like this:
def bin_int(number, size=8):
    max_val = int('0b' + ('1'* (size - 1)), 2)  # e.g. 0b01111111
    assert -max_val <= number <= max_val, 'Number out of range'
    if number >=0:
        return bin(number)
    sign = int('0b1' + ('0' * size), 2)  # e.g. 0b10000000
    return bin(number + sign)

Now, to do what you initially wanted: write the binary representation of numbers to a file.
output_list = [1, -1, -5, -64, 0]  # iterable *containing* integers
with open(filename, 'w') as output_file:  # with statement is safer for writing
    for number in output_list:
        output_file.write(bin_int(number) + '\n')

Or if you just want to check the result:
print([bin_int(number) for number in [1, -1, -5, -64, -127]])
# ['0b1', '0b11111111', '0b11111011', '0b11000000', '0b10000001']

Note that if you want to strip the 0b, you can do that via bin_int(number)[2:], e.g. output_file.write(bin_int(number)[2:] + '\n'). This removes the first two characters from the string holding the binary representation.

