Home > other >  Pickle. Loads have bosses can explain how the relief of paramagnetic?
Pickle. Loads have bosses can explain how the relief of paramagnetic?

Time:11-04

First of all, it loads only parse the data first, if the string of bytes is multiple data, the data behind the parsing,

More reasonable approach is to create a temporary file and loads, but here I want to know what really no more convenient method loads? Here tried two ways, one is each byte violence to try, one is the dump again, get the length, simulate the load of pointer,

But there is no method loads and returns a parsing length?

 
The import pickled
F=b '\ x80 \ x04 \ x95 \ x07 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x8c \ x03123 \ x94 \ x80 \ x04 \ x95 \ x07 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x8c \ x03456 \ x94'
For I in range (len (f)) :
Try:
J=pickle loads (f [I:])
Except: pass
The else: print (j)
#
123
123
123
456
456
456

52.9 mu s
Three times in the same data is parsed

 
# % % timeit
The import pickled
F=b '\ x80 \ x04 \ x95 \ x07 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x8c \ x03123 \ x94 \ x80 \ x04 \ x95 \ x07 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x8c \ x03456 \ x94'
I=0
L=len (f)
While 1:
J=pickle loads (f [I:])
Print (j)
Lj=len (pickle. Dumps (j))
I +=lj
If I==l: break
#
123
456

3.35 u s
  • Related