Aug-14-2018, 02:16 PM
(This post was last modified: Aug-14-2018, 02:16 PM by sripylearn.)
Traceback (most recent call last):
File "C:/-Prsnl/learning/python/VzPyinP/vzPylib/vzPyfunc.py", line 141, in <module>
print(" The Return of Get Struct Splicer {%s}" % format(get_array_struct(lines = samplelines)))
File "C:/-Prsnl/learning/python/VzPyinP/vzPylib/vzPyfunc.py", line 135, in get_array_struct
fields = parse(x = lined)
File "C:/-Prsnl/learning/python/VzPyinP/vzPylib/vzPyfunc.py", line 130, in <lambda>
parse = lambda x: tuple(s.decode() for s in unpack(x.encode()))
struct.error: unpack_from requires a buffer of at least 275 bytes
File "C:/-Prsnl/learning/python/VzPyinP/vzPylib/vzPyfunc.py", line 141, in <module>
print(" The Return of Get Struct Splicer {%s}" % format(get_array_struct(lines = samplelines)))
File "C:/-Prsnl/learning/python/VzPyinP/vzPylib/vzPyfunc.py", line 135, in get_array_struct
fields = parse(x = lined)
File "C:/-Prsnl/learning/python/VzPyinP/vzPylib/vzPyfunc.py", line 130, in <lambda>
parse = lambda x: tuple(s.decode() for s in unpack(x.encode()))
struct.error: unpack_from requires a buffer of at least 275 bytes
def get_array_struct(lines): start_time = time.time() fieldwidths = (2, 10, 24,10,20,20,30,20,20,10,20,89) # negative widths represent ignored padding fields fmtstring = ''.join('{}{}'.format(abs(fw), 'x' if fw < 0 else 's') for fw in fieldwidths) fieldstruct = struct.Struct(fmtstring) if sys.version_info[0] < 3: parse = fieldstruct.unpack_from else: # converts unicode input to byte string and results back to unicode string unpack = fieldstruct.unpack_from parse = lambda x: tuple(s.decode() for s in unpack(x.encode())) # print('fmtstring: {!r}, recsize: {} chars'.format(fmtstring, fieldstruct.size)) line_array_dic_map = [] for lined in lines: fields = parse(x = lined) line_array_dic_map.append(fields) print("get_array_struct timing --- %s seconds ---" % (time.time() - start_time)) return line_array_dic_map