python - Convert list containing tuple to string -
python - Convert list containing tuple to string -
i have list containing tuples. need convert entire list string compression. code worked fine in python 2.7:
tt = '{}'.format(tt) but in python 2.6 next error:
hist = '{}'.format(hist) valueerror: 0 length field name in format the info in tt looks [(2, 3, 4), (34, 5, 7)...]
any workaround this, apart upgrading python version?
put index in replacement field:
tt = '{0}'.format(tt) or use:
tt = str(tt) which back upwards versions of python prior introduction of str.format in 2.6.
demo:
>>> tt = [(2, 3, 4), (34, 5, 7)] >>> "{0}".format(tt) '[(2, 3, 4), (34, 5, 7)]' >>> str(tt) '[(2, 3, 4), (34, 5, 7)]' python runtime-error
Comments
Post a Comment