[Tutor] Doing the Right Thing when converting strings to numbers

dman dman@dman.ddts.net
Mon, 20 May 2002 15:32:24 -0500


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

On Mon, May 20, 2002 at 05:39:10PM +0100, Michael Williams wrote:
| On Mon, May 20, 2002 at 04:40:15PM +0100, ibraheem umaru-mohammed wrote:
| > [Michael Williams wrote...]
| > -| Hi,
| > -|=20
| > -| I'd like to convert a string to either a float or an integer
| > -| ``intelligently", i.e.:
=2E..
| I think you've misunderstood as I wasn't clear enough. I want to use the
| *same* function to do the conversion to both float and int.
=2E..

def clever_coerce( s ) :
    if s.find( '.' ) !=3D -1 :
        return float( s )
    else :
        return int( s )
=20

--=20

But As for me and my household, we will serve the Lord.
        Joshua 24:15
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


--EVF5PPMfhYS0aIcm
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

iEYEARECAAYFAjzpXVgACgkQO8l8XBKTpRQLVQCcCB/bJTz5IPl9WpUpUEKnQl+V
EZAAoID1a6B6I0g8iKMUR5UIhC2HTv+3
=iFOM
-----END PGP SIGNATURE-----

--EVF5PPMfhYS0aIcm--