Peter Otten wrote: > Chris wrote: > > >> >>> re.split('x', '1x2X3', re.I) >>['1', '2X3'] > > > >>I expected ['1', '2', '3'] but in this case re.I bahaves exactly as not >>present at all... > > > >>Is that an expected behaviour or a fault? > > > This is expected: > > >>>>help(re.split) > > Help on function split in module sre: > > split(pattern, string, maxsplit=0) > Split the source string by the occurrences of the pattern, > returning a list containing the resulting substrings. > > You are setting maxsplit to > > >>>>re.I > > 2 > > Use re.compile() to get the desired behaviour: > > >>>>re.compile("x", re.I).split("1x2X3") > > ['1', '2', '3'] > > Peter
thanks, I should read the docs but but more of a basic question following, I was doing the following before: method = 'split' # came from somewhere else of course result = re.__dict__[method].(REGEX, TXT) precompiling the regex r = compile(REGEX) does give an regex object which has the needed methods print dir(r) ['__copy__', '__deepcopy__', 'findall', 'finditer', 'match', 'scanner', 'search', 'split', 'sub', 'subn'] but how do I evaluate them without explicitly calling them? result = r.__???MAGIC???__[method](TXT) obviously I am not a Python pro ;) thanks chris -- http://mail.python.org/mailman/listinfo/python-list