a Python bug in processing __del__ method ??
Today I was playing with a small Python program using Python 2.4 on Cygwin (up-to-date version, on Windows XP), but ran into a strange error on the following small program (named bug.py): --- #!/usr/bin/python class Person: population = 0 def __del__(self): Person.population -= 1 peter = Person() --- The error returned is this: $ python bug.py Exception exceptions.AttributeError: "'NoneType' object has no attribute 'population'" in > ignored However, if I rename variable name 'peter' to something like 'peter1' or 'david', the error is gone. Looks to me the error only happens to variable name 'peter'. Does anyone know what is wrong? Is this a bug only on Cygwin? - Baoqiu -- http://mail.python.org/mailman/listinfo/python-list
Re: a Python bug in processing __del__ method ??
Fredrik and Steve, Thank you so much for the help. Now I know more about Python. :-) Steve's test does explain why 'peter1' is OK while 'peter' is not: 'peter1' appears before 'Person' in the globals while 'peter' is after. The error message is just a little confusing to a Python newbie, I think. Thanks again! - Baoqiu -- http://mail.python.org/mailman/listinfo/python-list
Re: deleting texts between patterns
John Machin <[EMAIL PROTECTED]> writes: > Uh-oh. > > Try this: > >>>> pat = re.compile('(?<=abc\n).*?(?=xyz\n)', re.DOTALL) >>>> re.sub(pat, '', linestr) > 'blahfubarabc\nxyz\nxyzzy' This regexp still has a problem. It may remove the lines between two lines like 'aaabc' and 'xxxyz' (and also removes the first two 'x's in 'xxxyz'). The following regexp works better: pattern = re.compile('(?<=^abc\n).*?(?=^xyz\n)', re.DOTALL | re.MULTILINE) >>> lines = '''line1 ... abc ... line2 ... xyz ... line3 ... aaabc ... line4 ... xxxyz ... line5''' >>> pattern = re.compile('(?<=^abc\n).*?(?=^xyz\n)', re.DOTALL | re.MULTILINE) >>> print pattern.sub('', lines) line1 abc xyz line3 aaabc line4 xxxyz line5 >>> - Baoqiu -- Baoqiu Cui -- http://mail.python.org/mailman/listinfo/python-list