[Tutor] Re: more problems, my final questions

Derrick 'dman' Hudson dman@dman.ddts.net
Thu, 11 Jul 2002 10:43:00 -0500


--DBIVS5p969aUjpLe
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Jul 10, 2002 at 10:28:03AM -0700, Jeff Shannon wrote:
| Kyle Babich wrote:
|=20
| > Anyway, I came up with a work around where I write sleeptime to a
| > temporary file and extract it later.

That is unnecessary.  I recommend reading some documents or tutorials
on structured programming.  (sorry, I don't have any URLs handy)  The
specific areas to study are how local variables are handled, and how
argument passing is done.

[...]
| > Why can't I do that?
|=20
| When you read something from a file, you get a string object.  Strings do=
n't
| allow arithmetic -- you need to convert the string into an integer first.

Actually, a string can be multiplied by an integer.  It is convenient
when you want the same string to be repeated multiple times since you
don't need to go through a loop to do it.

>>> print '-'*60
------------------------------------------------------------
>>>

Since python is strongly typed, the result of the '*' operator depends
on what type of objects you are multiplying.  When a string is
multiplied by an integer, it repeats itself.  The same thing is true
for a list or a tuple.  It is not automagically converted to an
integer, ignoring all errors, and then multiplied as an integer.
Another example of the polymorphism that strong typing provides is
list (or string or tuple) addition :
    >>> print [1] + [2]
    [1, 2]
    >>>
with lists (as with strings and tuples), the '+' operator means to
concatenate the two sequences.

HTH,
-D

--=20
=20
A perverse man stirs up dissension,
and a gossip separates close friends.
        Proverbs 16:28
=20
http://dman.ddts.net/~dman/


--DBIVS5p969aUjpLe
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj0tp4MACgkQO8l8XBKTpRTnyQCeOyEWbqg7Ar5CBFNVEsFYQMvm
jGQAn3Oy7cyo96uRGxkVd9rpqRMsE10W
=Y0na
-----END PGP SIGNATURE-----

--DBIVS5p969aUjpLe--