def close(self):
    if self.bitCount % 8 != 0:
        super(BitFile, self).write(chr(self.byte))
super(BitFile, self).close()
with BitFile('bitfile.bin', 'w') as bf:
    bf.write(1)
bf.write(1)
bf.write(1)
bf.write(0)
bf.write(0)
bf.write(0)
bf.write(0)
bf.write(0)
bf.write(1)
writing 'bits' to c++ file streams