Re: Regular expression for not-group
You want to use negative lookahead eg.\.(?!py)it matches only if the characters ahead in the regex don't match the pattern in the brackets.
http://docs.python.org/lib/re-syntax.html (about halfway down the page)On 15 Jun 2006 14:11:39 -0700,
Chris Lasher <[EMAIL PROTECTED]> wrote:
Is it possible to write a regular _expression_ such that a "match" isfound provided the string does not match a group in the regex? Let megive a concrete example.Suppose I want to find a match to any filename that does not end in
.py, (ignoring the obvious use of the .endswith('.py') string method).I tried the things that were obvious to me, none of which worked.\.^(py)\.(^py)\.[^p][^y]The last one deceived me at first because it will match "
spam.spam",but not "spam.parrot". I'm a bit stumped at this point. If this can bedone with a regular _expression_, I'd love to know how, and even if itcan't be, that would be very helpful to know, too.
Many thanks in advance,Chris--http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list
module with __call__ defined is not callable?
Hi All.I was wondering why defining a __call__ attribute for a module doesn't make it actually callable.I don't have any reason for doing so, I was just wondering if it worked, and found out it didn't.$ cat mod.py"""Test callable module"""def __call__(): return "in mod.__call__">>> import mod>>> mod()Traceback (most recent call last): File "", line 1, in ?TypeError: 'module' object is not callable>>> mod.__call__()'in mod.__call__'Thanks for any replies, Adam. -- http://mail.python.org/mailman/listinfo/python-list
Re: module with __call__ defined is not callable?
Thanks for you answer.I was under the impression that you could tack methods onto an object at any time, your example almost works with old style classes and would with a function instead of a method.>>> class A: ... def __init__(self):... self.__call__ = A.hello... def hello(self):... print "Hello, world!"...>>> a = A()>>> a()Traceback (most recent call last): File "", line 1, in ?TypeError: unbound method hello() must be called with A instance as first argument (got nothing instead)>>> a(a)Hello, world!>>>So now all I need to know is why now with new style classes the special functions need to be defined on the class instead of attached to the instance at any time. On 08/02/06, Delaney, Timothy (Tim) <[EMAIL PROTECTED]> wrote: adam johnson wrote:> Hi All.> I was wondering why defining a __call__ attribute for a module> doesn't make it actually callable.For the same reason that the following doesn't workclass A (object): def __init__(self):self.__call__ = A.hellodef hello (self):print 'Hello, world!'a = A()a()Traceback (most recent call last): File "D:\Python\modules\testclasscall.py", line 10, in ?a()TypeError: 'A' object is not callableThe __call__ attribute must be defined on the class (or type) - not onthe instance. A module is an instance of . Tim Delaney--http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
