[Tutor] Two questions

Alexandre Ratti alex@gabuzomeu.net
Thu, 02 May 2002 12:20:41 +0200


Hello Henry,


At 00:49 02/05/2002 -0400, you wrote:
>Date: Wed, 01 May 2002 23:47:48 -0500
>From: Henry Steigerwaldt <hsteiger@comcast.net>
>Subject: [Tutor] Two questions

>How can one append different types of variables together and store into a 
>variable?
>
>For example, in the Tcl language, one can do the following:
>
>append site_id "$day$ob_time  $wind  $temp/$dwpt  A$pres$equal_sign"

Here is a Python equivalent:

site_id = "%s%s%s" % (site_id, aValue, anotherValue)

Basically, you specify a string "template" and insert variable values into it.

Example:

 >>> titi = 0.1
 >>> toto = 1
 >>> tutu = "truc"
 >>> print "%s-%s-%s" % (titi, toto, tutu)
0.1-1-truc

For more details, see:

http://www.python.org/doc/current/lib/typesseq-strings.html

>I also see that one can change a string into an integer using string.atoi, 
>but I cannot find a funtion that changes an integer or float into a 
>string. Is there one in Python?

You can use the str() function.

>Finally, is there a Web link that one can go to that describes each 
>function in each Python module? For example, if I wanted to know what 
>functions are available in the "time" or "string" modules, along with 
>descriptions of each funtion and examples of how to use each, where can 
>one go to get this information.

You want the "Python Library Reference"; it is part of the standard Python 
doc. See:

http://www.python.org/doc/

If you run Windows, the doc in HTML help format is very handy:

http://www.orgmf.com.ar/condor/pytstuff.html#python



Cheers.

Alexandre