Python -% d format, not a list

I am trying to print a data value from a list to a file. The error keeps on typing that

TypeError: %d format: a number is required, not list

      

I don't seem to understand ... when I try to print each one individually to the screen, I have no problem. Can you see where the problem might be?

   print >>map_file0, "%d,%d,%d" % (coreid[0],ret_perf[0][0],llc_perf[0][0])

      

thank

+3


source to share


2 answers


If you are using newer string formatting , there is no need to specify the type.



# old
old_method = "%d,%d,%d" % (1, 2, 3)

# new (2.7)
new_method = "{},{},{}".format(1, 2, 3)

      

+2


source


Based on python documentation here , %d

- Signing integer decimal . Indicates that one or more of the values ​​you are trying to format are lists, not integers. You may have a list of lists.



+1


source







All Articles