1. Olivier Lauzanne
  2. pyquery
  3. Issues
Issue #15 resolved

AttributeError on $(this)

Rooney Panduwana
created an issue

Using $(this) inside callback function (eg. for filter or map) gives AttributeError. Here's sample code to reproduce the error (where S here is like $ in javascript):


from pyquery import PyQuery src = """ ... <ol> ... <li>Coffee</li> ... <li>Tea</li> ... <li>Milk</li> ... </ol> ... """ S = PyQuery(src) S('li').map(lambda i, el: S(this).html()) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "pyquery.py", line 436, in map result = func(i, element) File "<stdin>", line 1, in <lambda> File "pyquery.py", line 146, in call if len(args) == 1 and not args[0].startswith('<'): AttributeError: 'HtmlElement' object has no attribute 'startswith' }}}

Expected behavior: no error, returns ['Coffee', 'Tea', 'Milk']

My patch is attached.

Comments (5)

  1. Log in to comment