Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8041

Python • Re: Problem with print in a for loop.

$
0
0
With this code I am trying to make a line break after every row,

Code:

query = “SELECT * FROM sensorlog”c.execute(query)for row in c:print(“%s\n” % ("Temperature ",row[1], "C Humitidy ", row[2], "% Date ", row[3]))
but I get this errormessage

TypeError: not all arguments converted during string formatting

Code:

Can someone help me with this problem?

No indentation before print puts it outside the for loop. But that's not what's causing the error. Your use of % substitution is incorrect.

You should have one string to the left of the % with multiple occurrences of %s in it indicating where the values go:

Code:

print(“Temperature %sC Humitidy %s Date %s” % (row[1], row[2], row[3]))
You also don't need the \n unless you want a blank line between outputs.

Statistics: Posted by thagrol — Mon Dec 15, 2025 12:46 pm



Viewing all articles
Browse latest Browse all 8041

Trending Articles