[Python-Dev] other "magic strings" issues

Jp Calderone exarkun at intarweb.us
Fri Nov 7 18:50:13 EST 2003


On Fri, Nov 07, 2003 at 09:35:26AM -0800, Guido van Rossum wrote:
> > > Yes, that would be good.  Is there anything besides maketrans() in the
> > > string module worth saving?  (IMO letters and digits etc. are not --
> > > you can use s.isletter() etc. for that.)
> > 
> > I'm not following, are you saying we don't need string.ascii_letters and
> > friends any more?
> 
> Hm, I'd forgotten about ascii_letters.  It would make a beautiful
> class attribute of str.
> 
> I *do* think that we don't need string.letters -- the only use for it
> I've seen is checking if a character is in that string, and
> c.isletter() is faster.  But if someone has a use case for it that
> isn't argued away, I'd be okay with seeing it reincarnated as a class
> attribute of str too.
> 


  How about this use case?

    def genPassword(pickFrom=string.letters+string.digits, n=8):
        return ''.join([random.choice(pickFrom) for i in range(n)])

  Jp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.python.org/pipermail/python-dev/attachments/20031107/19059b4b/attachment-0001.bin


More information about the Python-Dev mailing list