can %s be an integer? *Python code* -


looking @ django code djangobook:

from django.http import http404, httpresponse import datetime  def hours_ahead(request, offset):     try:         offset = int(offset)     except valueerror:         raise http404()     dt = datetime.datetime.now() + datetime.timedelta(hours=offset)     html = "<html><body>in %s hour(s), %s.</body></html>" % (offset, dt)     return httpresponse(html) 

after try, converts offset integer, right? , in line 'datetime.timedelta(hours=offset)', offset used integer, in line 'html = "in %s hour(s), %s." % (offset, dt)'

offset %s string, right? or miss understanding? thought %s can string, not integer?

%s calls str() method on corresponding argument... (similar %r calls repr()) - either of can used any object... unlike %d (%i same) , %f instance require appropriate types.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -