Reloading modules

Delaney, Timothy tdelaney at avaya.com
Mon Feb 25 18:39:21 EST 2002


> From: Jeff Shannon [mailto:jeff at ccvcorp.com]
> 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.

That's why *I* used a slice. However, the following will work ...

if file[-1:] in 'co':
    file = file[:-1]

which is probably the most consise way. Using a sequence containing strings
is the more general form though, for when you need to check more than a
single character.

Tim Delaney




More information about the Python-list mailing list