[Tutor] Two questions

Timothy M. Brauch tbrauch@tbrauch.com
Thu, 2 May 2002 00:57:05 -0400


I'll leave the first question to someone better suited to answer it, but I
can try to answer the other two.

>To All:
>
>Question # 1
>
>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"
>
>The above example appends to the variable site_id, all the other variables
located
>to the right. This piece of code appends different types of data together,
integers,
>floats, and characters or strings (i.e. the letter A, and the equal sign).
And notice
>that site_id will also contain the spaces located between some of the
variables.
>
>There is a string.join function in Python, but this is used only to join
different
>"strings" together. I cannot however find an example of how to combine
different
>data forms together (strings, integers, floats, etc.) like my example above
does in
>Tcl.
>
>Question # 2
>
>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? I bet
>there is! The Quick Python Book that I have does not show one.
>
Try using str(x) to change x into a string.  Similarly, you can use int(x)
to attempt to change x into an int and float(x) to change x into a float.
And, if you are so inclined, you can do float(str(int(x))).  I'll leave it
up to you to guess what the final result is.
>
>Question # 3
>
>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.
>
One thing to check is the online Module index available at
<http://www.python.org/doc/current/modindex.html>   That will explain most
of the modules, and it is easy to find the specific one you are looking for.
The other thing is to play around with the dir(x) function.  It should tell
you what you can do to x.  And, if the module is coded nicely, you can try a
print x.__str__() and see where that gets you.
>
>Thanks much ahead of time to anyone that responds!
>
>Henry Steigerwaldt
>Hermitage, TN

 - Tim