#!/usr/bin/python
#filename:test15.py
import struct
with open('myfile.zip','rb') as f:
data = f.read()
# print(data)
start = 0
for i in range(2):
start += 14
fields = struct.unpack("<IIIHH",data[start:start+16])
crc32,comp_size,uncomp_size,filenamesize,extra_size = fields
start += 16
filename = data[start:start+filenamesize]
start += filenamesize
extra = data[start:start+extra_size]
print(filename,hex(crc32),comp_size,uncomp_size)
start += extra_size + comp_size
import threading,zipfile
class AsyncZip(threading.Thread):
def __init__(self,infile,outfile):
threading.Thread.__init__(self)
self.infile = infile
self.outfile = outfile
def run(self):
f = zipfile.ZipFile(self.outfile,'w',zipfile.ZIP_DEFLATED)
f.write(self.infile)
f.close()
print('Finished backgroud zip of:',self.infile)
background = AsyncZip('mydata.txt','myarchive.zip')
background.start()
print('The main program continues to run in foreground.')
background.join()
print('Main program waited until background was done.')
import logging
logging.debug('debugging information')
logging.info('informational message')
logging.warning('Warning:config file %s not found','server.conf')
logging.error('Error occurred')
logging.critical('Critical error -- shutting down')
import weakref,gc
class A:
def __init__(self,value):
self.value = value
def __repr__(self):
return str(self.value)
a = A(10)
d = weakref.WeakValueDictionary()
d['primary'] = a
print(d['primary'])
del a
gc.collect()
from array import array
a = array('H',[4000,10,700,22222])
print(sum(a))
print(a[1:3])
from collections import deque
d = deque(['task1','task2','task3'])
d.append('task4')
print('Handling',d.popleft())
import bisect
scores = [(100,'perl'),(200,'tcl'),(400,'lua'),(500,'python')]
bisect.insort(scores,(300,'ruby'))
print(scores)
from heapq import heapify,heappop,heappush
data = [1,3,5,7,9.2,4,6,8,0]
heapify(data)
heappush(data,-5)
[heappop(data) for i in range(3)]
from decimal import *
aa = round(Decimal('0.70')*Decimal('1.05'),2)
print(aa)
print(.70*1.05,2)
print(sum([Decimal('0.1')]*10))
print(sum([0.1]*10))