Question: Is there anyway that

```
>>> int('0000001',2)
1

```

Could save the leading 0s ?

What I want to do is, with a huge string of bits, in 8 and 8 bits I would convert to int, and then to char, and write it all in a file. 
Later I would want to read the file, get the char, use ord(), get the int, and then the bits that I entered, with the leading 0s.

Answer: 
You can preserve the number of initial zeroes by finding the first index of `1` (as it is a binary string). 

```
>>> s = '0000001'
>>> '{}{}'.format('0'*s.index('1'),int(s,2))
'0000001'
>>> s = '0000011'
>>> '{}{}'.format('0'*s.index('1'),int(s,2))
'000003'

```

As you can see, only the leading zeroes are preserved and not the number of digits. 

Another implementation (only zeroes included)

```
>>> def change(s):
...      try:
...           return '{}{}'.format('0'*s.index('1'),int(s,2))
...      except ValueError:
...           return s
... 
>>> change('000000')
'000000'
>>> change('000001')
'000001'
>>> change('000011')
'00003'

```
An OOP oriented solution to your problem could be to create a `Binary` class which stores the information about the leading zeroes.

```
class Binary(object):

    def __init__(self, strval):
        object.__init__(self)
        self._leading_zeroes = 0
        self._int_repr = 0
        self._str_val = strval
        self._toBinary()

    def _toBinary(self):
        for c in self._str_val:
            if c=='0': self._leading_zeroes += 1
            else: break

        try: self._int_repr = int(self._str_val,2)
        except ValueError as e: raise e

    def GetLeadingZeroes(self):
        return ''.join(['0' for i in xrange(self._leading_zeroes)])

    def GetIntRepr(self):
        return self._int_repr

    def __repr__(self):
        return self.__unicode__()

    def __str__(self):
        return '%s%s' % (self.GetLeadingZeroes(), '' if self.GetIntRepr()==0 else '{0:b}'.format(self.GetIntRepr()))

    def __unicode__(self):
        return unicode(self.__str__())

if __name__ == '__main__':
    b0 = Binary('000001')
    b1 = Binary('000000')
    b2 = Binary('001001')
    print b0, b1, b2

#output: 0000001 0000000 0001001

```

Then, if you need to perform operations on Binary objects. you could simply overload the operators of the Binary class.