Hi Alan, Alan G wrote on 11.08.2005:
>> I will combine Kent's and your suggestion, because he included a >> check for an AttributeError: >> > >OK, as a slightly more perl-ish solution to the no Attribute problem >you could also do this: > >try: > type = re.search('\w+', parameters['type'].value).group() or >'page' >except KeyError: > type = 'page' > Are you sure? >>> a = 'abcd' >>> import re >>> type = re.search('\d+',a).group() or 'page' Traceback (most recent call last): File "<stdin>", line 1, in ? AttributeError: 'NoneType' object has no attribute 'group' If the search does not succeed, the returned object has the value None, which has no attribute group. Thanks, Jan -- There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. - Jeremy S. Anderson _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor