Reloading modules

Jeff Shannon jeff at ccvcorp.com
Fri Feb 22 13:14:36 EST 2002


Steve Holden wrote:

>
> if file[-1] in "co":
>     file = file[:-1]

Given the source of 'file' in this case, this is probably not
significant, but there's a possible gotcha here if empty strings are a
possibility.

>>> empty = ''
>>> empty[-1]
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
IndexError: string index out of range
>>> empty[-1:]
''
>>>

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list