Re: check object being a compiled regular expression

2006-03-25 Thread Diez B. Roggisch
Helmut Jarausch schrieb: > Hi, > sorry, this seems to be a FAQ but I couldn't find anything > > I need to check if an object is a compiled regular expression > > Say > import re > RX= re.compile('^something') > > how to test > > "if RX is a compiled regular expression" > > type(RX) says > >

Re: check object being a compiled regular expression

2006-03-25 Thread James Thiele
This is crude, but works: >>> import re >>> RX= re.compile('^something') >>> str(RX).find("<_sre.SRE_Pattern") == 0 True -- http://mail.python.org/mailman/listinfo/python-list

check object being a compiled regular expression

2006-03-25 Thread Helmut Jarausch
Hi, sorry, this seems to be a FAQ but I couldn't find anything I need to check if an object is a compiled regular expression Say import re RX= re.compile('^something') how to test "if RX is a compiled regular expression" type(RX) says but if isinstance(RX,_sre.SRE_Pattern) and if isinstanc