Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - %d format , not list [closed]

Tags:

python

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

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

I don't seem to understand.. when I am trying to print each of them individually on the screen I don't have any problem. Can you see where the problem could be?

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

Thanks

like image 514
rnish Avatar asked Dec 31 '25 10:12

rnish


1 Answers

If you use the 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)
like image 178
monkut Avatar answered Jan 02 '26 01:01

monkut