Debugging Builds
Hi, Is there any documentation concerning the Python debugging builds beyond section 1.5 in the Python/C API reference manual and Misc/ SpecialBuilds.txt file in the source code? I'd like to know how people generally go about debugging memory leaks in C extensions. Thanks, David -- http://mail.python.org/mailman/listinfo/python-list
Re: Beautiful Soup Question: Filtering Images based on their width and height attributes
> Hello, > > I want to extract some image links from different html pages, in > particular i want extract those image tags which height values are > greater than 200. Is there an elegant way in BeautifulSoup to do this? Yes. soup.findAll(lambda tag: tag.name=="img" and tag.has_key("height") and int(tag["height"]) > 200) -- http://mail.python.org/mailman/listinfo/python-list
changing value of 'self' when subclassing int
I'd like to subclass int to support list access, treating the integer as if it were a list of bits. Assigning bits to particular indices involves changing the value of the integer itself, but changing 'self' obviously just alters the value of that local variable. Is there some way for me to change the value of the BitSequence object itself? I've also tried wrapping and delegating using __getattr__, but I couldn't figure out how to handle in-place methods. Thanks for your help, David Coffin class BitSequence(int): """An integer emulating a sequence of bits, subclassing int.""" def __new__(cls, value, length=32): inst = super(BitSequence,cls).__new__(cls, value) inst.length = length return inst def __setitem__(self, index, bit): mask = 1 << self.length - index - 1 if bit == 1: # XXX only changing local 'self' self |= mask elif bit == 0: self &= ~mask def __getitem__(self, i): return (self >> (self.length - i -1)) & 1 def __repr__(self): s = '' for i in xrange(self.length): s = str(self >> i & 1) + s return s + " : " + str(self) -- http://mail.python.org/mailman/listinfo/python-list
Re: changing value of 'self' when subclassing int
Thanks for all the help. > On 20 Feb 2006, at 17:34, Alex Martelli wrote: > > ...integers are immutable, like all other numbers in Python: there > is NO > way to "change the value of the integer itself". So, on learning that I could subclass the number types, I didn't even consider the fact that they're immutable. I feel slightly foolish. And I'll look at gmpy straight away, it looks like it contains functionality I'll find useful. > On 21 Feb 2006, at 10:58, Fuzzyman wrote: > > Probably your best bet is to have the assignment done as a method call > which returns the new value. I not sure that would be suitable in this case. I'm using genetic algorithm code containing some methods that assume 'individuals' are represented as bitstrings, and some that assume individuals are represented as lists of integers. Ideally, I could have created a class for the bitstring individuals that also supported list based bit assignment (without too much overhead). Best wishes, David Coffin -- http://mail.python.org/mailman/listinfo/python-list
Monkey patching new style classes
Is it possible to add an attribute to a new style class where the name of that attribute is determined at runtime? In other words, is there an new style class alternative to adding items to a classes __dict__ ? Thanks. -- http://mail.python.org/mailman/listinfo/python-list