MCPcopy Create free account
hub / github.com/gawel/pyquery / Fn

Class Fn

pyquery/pyquery.py:1493–1511  ·  view source on GitHub ↗

Hook for defining custom function (like the jQuery.fn): .. sourcecode:: python >>> fn = lambda: this.map(lambda i, el: PyQuery(this).outerHtml()) >>> PyQuery.fn.listOuterHtml = fn >>> S = PyQuery( ... ' Coffee Tea Milk</

Source from the content-addressed store, hash-verified

1491 return self
1492
1493 class Fn(object):
1494 """Hook for defining custom function (like the jQuery.fn):
1495
1496 .. sourcecode:: python
1497
1498 >>> fn = lambda: this.map(lambda i, el: PyQuery(this).outerHtml())
1499 >>> PyQuery.fn.listOuterHtml = fn
1500 >>> S = PyQuery(
1501 ... '<ol> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ol>')
1502 >>> S('li').listOuterHtml()
1503 ['<li>Coffee</li>', '<li>Tea</li>', '<li>Milk</li>']
1504
1505 """
1506 def __setattr__(self, name, func):
1507 def fn(self, *args, **kwargs):
1508 func.__globals__['this'] = self
1509 return func(*args, **kwargs)
1510 fn.__name__ = name
1511 setattr(PyQuery, name, fn)
1512 fn = Fn()
1513
1514 ########

Callers 1

PyQueryClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected