def word2str(zahl): if zahl < 0: zahl = zahl + 65536 a, b = map(chr, divmod(zahl, 256)) return b + a def str2word(bytes): a =ord(bytes[1])*256+ord(bytes[0]) if a > 32767: a = a - 65536 return a class openintfile: """Klasse, die ein File of SmallInteger bedient, das sind 2 Byte-Integerwerte im Wertebereich von -32768 ... +32767 """ def __init__(self, filename, modus): self.modus = modus self.file = open(filename, self.modus) def write(self, zahl): self.file.write(word2str(zahl)) def read(self): a = self.file.read(2) return str2word(a) def close(self): self.file.close() f = openintfile('intfile', 'w') f.write(-1300) f.close() f = openintfile('intfile', 'r') print f.read() f.close()