FW: RE: [Tutor] Generating random in a user specified range.

Crabtree, Chad Chad.Crabtree at nationalcity.com
Tue Apr 27 13:02:57 EDT 2004



-----Original Message-----
From: Crabtree, Chad 
Sent: Tuesday, April 27, 2004 1:02 PM
To: 'Magnus Lycka'
Subject: RE: RE: [Tutor] Generating random in a user specified range.


> Chad Crabtree wrote:
> > you need to strip the stuff from this.  I would do it thus.  
> > import string
> > bottom=int(string.strip(strbottom))
> > top=int(string.strip(strtop))
> > 
> > this gets ride of any string whitespace strangeness that 
> canot be converted
> > to an integer.
> 
> There is no need to do that:
> 
> >>> 2 * int('    45     \n')
> 90
> 
> Besides, the string module is more or less made redundant 
> since several
> python versions back. Use " a string ".strip() instead of 
> string.strip(" a string ")
> 
Thank you.  I always have a hard time with remembering the string methods.
I can only remember the string module.  IN addition I've had more troulbe
with the class methods than with the module.  I however cannot think of a
specific example.  IIRC it was with split not doing what I wanted it to.
Interestingly "".srtip() returns a new string instead of inplaceing the
change.  Is this because strings are immutable?  I'm thinking of lists
[].sort() method being inplace but lists are happily very mutable.

-------------------------------------------------------------------------------------------
***National City made the following annotations
-------------------------------------------------------------------------------------------

This communication is a confidential and proprietary business communication.
It is intended solely for the use of the designated recipient(s).  If this
communication is received in error, please contact the sender and delete this
communication.
===========================================================================================



More information about the Tutor mailing list