Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write integers to a file

Tags:

python

I need to write

ranks[a], ranks[b], count

to a file, each time on a new line

I am using:

file = open("matrix.txt", "w")
for (a, b), count in counts.iteritems():
    file.write(ranks[a], ranks[b], count)

file.close()

but this is not working and returns

TypeError: function takes exactly 1 argument (3 given)
like image 894
Julia Avatar asked Jan 19 '12 20:01

Julia


1 Answers

As the error says, file.write only takes one arg. Try:

file.write("%s %s %s" % (ranks[a], ranks[b], count))
like image 70
Hamish Avatar answered Oct 11 '22 22:10

Hamish