Is there any analog of perl's pack()/unpack() in Python?

Alexander Semenov sav at ulmen.mv.ru
Mon Dec 25 03:47:51 EST 2000


Hi!

Is there any way to read/write file with binary coded numbers in it?
I'm just tring to port this perl functions:
sub getlong {
        my($t);
        sysread FIL, $t, 4;
        return unpack('l',$t);
}

sub getfloat {
        my($t);
        sysread FIL, $t, 8;
        return unpack('d',$t)
}

etc...

I know, it's platform-dependent, but python has platform-dependent
modules and IEEE format is rather common.

Any suggestions?

Excuse me for my English, my native is Russian.

Thanks, Best Regards,
Alexander Semenov <sav at hey.to>






More information about the Python-list mailing list