screwdriver¶
Another tool for your python toolset. General odds and ends that kept coming up in projects.
Installation¶
$ pip install screwdriver
Supports¶
screwdriver has been tested with Python 2.7, 3.6 and 3.7
Docs & Source¶
Docs: http://screwdriver.readthedocs.io/en/latest/
Source: https://github.com/cltrudeau/screwdriver
Version: 0.14.0
Methods¶
-
class
screwdriver.
DictObject
(src)¶ Acts as a wrapper to a dictionary so that keys can be accessed as properties.
>>> d = DictObject({'x'=1, 'y'=2}) >>> d.x 1 >>> d._src {'x':1, 'y':2}
-
__init__
(src)¶
-
-
screwdriver.
dynamic_load
(name)¶ Equivalent of “from X import Y” statement using dot notation to specify what to import and return. For example, foo.bar.thing returns the item “thing” in the module “foo.bar”
-
screwdriver.
head_tail_middle
(src)¶ Returns a tuple consisting of the head of a enumerable, the middle as a list and the tail of the enumerable. If the enumerable is 1 item, the middle will be empty and the tail will be None.
>>> head_tail_middle([1, 2, 3, 4]) 1, [2, 3], 4
-
screwdriver.
list_to_rows
(src, size)¶ A generator that takes a enumerable item and returns a series of slices. Useful for turning a list into a series of rows.
>>> list(list_to_rows([1, 2, 3, 4, 5, 6, 7], 3)) [[1, 2, 3], [4, 5, 6], [7, ]]
-
screwdriver.
parse_link
(html)¶ Parses an HTML anchor tag, returning the href and content text. Any content before or after the anchor tag pair is ignored.
Parameters: html – Snippet of html to parse Returns: namedtuple(‘ParsedLink’, [‘url’, ‘text’]) Example:
>>> parse_link('things <a href="/foo/bar.html">Foo</a> stuff') ParsedLink('/foo/bar.html', 'Foo')
-
screwdriver.
pprint
(data)¶ Alternative to pprint.PrettyPrinter() that uses json.dumps() for sorting and displaying data.
Parameters: data – item to print to STDOUT. The item must be json serializable!
-
screwdriver.
rows_to_columns
(matrix)¶ Takes a two dimensional array and returns an new one where rows in the first become columns in the second.
\ Sort by:\ best rated\ newest\ oldest\
\\
Add a comment\ (markup):
\``code``
, \ code blocks:::
and an indented block after blank line