[Tutor] string formatting (%s)

Tiago Saboga tiagosaboga at terra.com.br
Sun Apr 16 02:40:19 CEST 2006


Can I use string formatting in my own functions, or is it stuck with builtins? 
It doesn't make much sense for me, but I don't understand the following 
error:

In [1]: var = 456

In [2]: def printd(arg):
   ...:     print('>>> %s') % arg
   ...:

In [3]: printd(var)
>>> 456

In [4]: printd('Variable is %s') % var
>>> Variable is %s
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most recent 
call last)

/home/tiago/<console>

TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'


Thanks,

Tiago.


More information about the Tutor mailing list