[Tutor] Looking for Python equivalents of some C functions

Don Arnold Don Arnold" <darnold02@sprynet.com
Fri Feb 7 07:10:02 2003


----- Original Message -----
From: "Tony Cappellini" <tony@tcapp.com>
To: <tutor@python.org>
Sent: Friday, February 07, 2003 1:19 AM
Subject: [Tutor] Looking for Python equivalents of some C functions


>
>
> Are there Python equivalents for the following C functions ?
>
> sprintf()

Take a look at http://www.python.org/doc/current/lib/typesseq-strings.html
and you'll see that you can use (almost?) all of C's string fromatting
operators in Python:

>>> a = 'This string has %d %s.' % (5,'words')
>>> print a
This string has 5 words.

> fprintf()

This can be done using the print statement:

myfile = open('temp')
print >> myfile, '%s %d %l' % ('stuff', 10, 28328738273L)

>
> I didn't see anything suitable in the strings module references.
>
> itoa()
> ltoa()
> ftoa()  // float or double to asciii

These are all covered by the built-in str( ) function:

>>> for i in (10, 2343224234234L, 4.52):
 print 'result = ' + str(i)

result = 10
result = 2343224234234
result = 4.52

HTH,
Don