[EMAIL PROTECTED] (Alex Martelli) wrote in
news:[EMAIL PROTECTED]:
> js <[EMAIL PROTECTED]> wrote:
>
>> HI guys,
>>
>> How do you write Perl's
>>
>> print a ... z, A ... Z, "\n"' in Python
>>
>> In Python?
>
> This specific one is easy, though this doesn't generalize:
>
> import string
> print string.lowercase + string.uppercase
>
> For the general case, there's no way to avoid calling chr and
> ord, because a string in Python doesn't have a "natural
> successor". So the only issue is how you prefer to hide those
> calls &c (in some class or function) and you already received
> suggestions on that.
>
No ord or chr in sight:
# Inclusive character range.
def pycrange(lo,hi):
import string
chars = string.letters + " "
rstr = ''
lp = chars.find(lo)
hp = chars.find(hi)
if lp < hp:
rstr = chars[lp:hp+1]
return rstr
print pycrange('c','n')
Lame code, though.
--
rzed
--
http://mail.python.org/mailman/listinfo/python-list