Fredrik Lundh schrieb: > "g.franzkowiak" wrote: > > >>I've read a pipe and store it in a object. >>My next step was the separation from 4 bytes with >>obj = string.join(list(dataObject)[:4] ==> '\x16 \x00 \x00 \x00' >>and the converting by >>value = struct.unpack('I', obj) generated the error >>"unpack str size does not match format" >> >>Unfortunately is len(obj) 7, but integer lengt 4. >>Why 7 ? > > > because string.join inserts a space between the bytes, by default (as > your example shows) > > if you really need that join(list) thing (it's not clear how you read it, but > I find it a bit hard to believe that you've managed to read it into some- > thing that's supported by list but not unpack), you can do > > obj = string.join(list(dataObject)[:4], "") > > or > > obj = "".join(list(dataObject[:4])) > > or some variation thereof. > > </F> > > >
I've also found the problem with som tests. The best of this was: tmpList = list(dataObject)[:4]) obj = tmpList[0]+tmpList[1]+tmpList[2]+tmpList[3]. But your suggestions are much better and new for me - both. Thanks gerd -- http://mail.python.org/mailman/listinfo/python-list