[Tutor] print method in Python2.7 problem
Mark Lawrence
breamoreboy at yahoo.co.uk
Sun Mar 15 18:40:08 CET 2015
On 15/03/2015 16:46, Doug Basberg wrote:
Nothing because it was in a completely unnecessary attachment (some
people won't even receive it), so here's the code.
Stat = {'Vbatt': 51.24, 'Ichrg': 6.75}
print ' <td style="text-align: center;">SOLAR PANEL VOLTAGE</td>'
print(' DSB "HI;" %s') % (str(Stat['Vbatt']))
print(' <td style="width: 50%; text-align: center;">%s</td>') %
(str(Stat['Vbatt']))
He also didn't bother specifying the actual problem,but like others here
we just love guessing games. So I'll go for:-
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str'
Print in 2.7 is a statement so the first one is fine. The second (and
third) you're trying to apply the % operator to the print statememt
which by definition is None, hence the error. You also don't need the
call to str so put it all together it simply becomes.
print ' DSB "HI;" %s' % Stat['Vbatt']
I'll leave you to come back with the next problem as I haven't worked
out what the solution is yet :)
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Tutor
mailing list