Issue #21 wontfix

each() returns an int

Anonymous created an issue

Hi,

I'm running python2.7 and always i try to use each() it returns an int value.

Here is my code: {{{

!python

import pyquery

def test(e): print e

if name == 'main': a = '<div><a>a1</a><a>a2</a><a>a3</a><a>a4</a><a>a5</a</div>' test = pyquery.PyQuery(a) test.children('a').each(lambda e: e.addClass('test')) }}}

When i try this an exception is raised with this message:

// File "main.py", line XX, in <lambda> test.children('a').each(lambda e: e.addClass('test')) AttributeError: 'int' object has no attribute 'addClass'//

is this a bug?

Thanks

Comments (1)

  1. Gael Pasgrimaud

    This is two ways to do what you want:

    test.children('a').each(lambda i,e: pyquery.PyQuery(e).addClass('test'))
    
    test.children('a').each(lambda: pyquery.PyQuery(this).addClass('test'))
    

    But yes, the doc is not clear..

  2. Log in to comment