[Python-de] Wie mach ich das in python:
Bertram Scharpf
lists at bertram-scharpf.de
Mit Jan 5 12:50:07 CET 2005
Hallo,
Am Mittwoch, 05. Jan 2005, 11:21:23 +0100 schrieb Christian Klinger:
> ich bin gerade dabei ein altes perl script zu pythonisieren.
>
> ####################################
> my $ts=time;
> print $ts;
> my @ts = ( (($ts & 0xff000000) >> 24),
> (($ts & 0xff0000) >> 16),
> (($ts & 0xff00) >> 8),
> (($ts & 0xff)) );
>
> print "\n";
> print @ts;
> print "\n";
>
> ###################################
>
> Kann mir jemand sagen was das macht, und wie kann man das in Python
> umsetzen?
Vielleicht so:
def timesplittobytes():
import time
t = int( time.time())
r = []
for i in [ j*8 for j in reversed( range( 4))]:
r.append( int( (t & (0xff << i)) >> i))
return r
Ein wenig eleganter wäre
r.append( int( t >> i) & 0xff)
Gruß
Bertram
--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de