简体   繁体   中英

ValueError: zero length field name in format with read and write

Does anybody know if it is possible to avoid the error ValueError: zero length field reading/writing from/to a file with Python 2.6.6 as specified in the following:

 File "format.py", line 26, in <module>
    for row in write_cols(rows):
  File "format.py", line 19, in write_cols
    return [col_spacer.join("{:<{width}}".format(col, width=widths[index]) for index, col in enumerate(row)) for row in data]
  File "format.py", line 19, in <genexpr>
    return [col_spacer.join("{:<{width}}".format(col, width=widths[index]) for index, col in enumerate(row)) for row in data]
ValueError: zero length field name in format

Change

"{:<{width}}".format(col, width=widths[index])

into

"{0:<{1}}".format(col, widths[index])

Coz in older release of python, you need to point out the order of multiple format field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM