Iteration of strings
Duncan Booth
duncan at NOSPAMrcp.co.uk
Mon Nov 25 06:17:42 EST 2002
Alan Kennedy <alanmk at hotmail.com> wrote in
news:3DE0DDEA.1B87D457 at hotmail.com:
> I suggest the following amendment:
>
> import types
>
> def dont_allow_string_argument(v):
> assert type(v) not in [types.StringType, types.UnicodeType]
Slightly better to write:
def dont_allow_string_argument(v):
assert type(v) not in types.StringTypes
Of course that still doesn't catch the case where someone subclassed a
string type. If you are sufficiently paranoid you might consider:
def dont_allow_string_argument(v):
for t in types.StringTypes:
assert not isinstance(v, t)
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list