Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docstrings to re_first and extract_first (closes #30) #33

Merged
merged 1 commit into from
Mar 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion parsel/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@ def css(self, xpath):

def re(self, regex):
"""
Call the ``.re()`` method for each element is this list and return
Call the ``.re()`` method for each element in this list and return
their results flattened, as a list of unicode strings.
"""
return flatten([x.re(regex) for x in self])

def re_first(self, regex):
"""
Call the ``.re()`` method for the first element in this list and
return the result in an unicode string.
"""
for el in iflatten(x.re(regex) for x in self):
return el

Expand All @@ -93,6 +97,10 @@ def extract(self):
return [x.extract() for x in self]

def extract_first(self, default=None):
"""
Return the result of ``.extract()`` for the first element in this list.
If the list is empty, return the default value.
"""
for x in self:
return x.extract()
else:
Expand Down