Emulate a printf() C-statement in Python???
John Machin
sjmachin at lexicon.net
Thu Mar 19 08:59:40 EDT 2009
On Mar 19, 11:43 pm, "Mr. Z" <no... at XSPAMbellsouth.net> wrote:
> I'm trying emulate a printf() c statement that does, for example
>
> char* name="Chris";
> int age=30;
> printf("My name is %s", name);
> printf("My name is %s and I am %d years old.", %s, %d);
>
> In other words, printf() has a variable arguement list the we
> all know.
>
> I'm trying to do this in Python...
>
| >>> def printf(fmt, *args):
| ... import sys
| ... sys.stdout.write(fmt % args)
| ...
| >>> printf("It's a %s %s parrot\n", 'Norwegian', 'blue')
| It's a Norwegian blue parrot
| >>>
HTH,
John
More information about the Python-list
mailing list