Mercurial > python-hglib
changeset 150:b94e1263836c
util: introduce strtobytes() (issue4520)
The strtobytes() function takes an object, gets its string
representation, and then convert that to bytes.
author | Brett Cannon <brett@python.org> |
---|---|
date | Thu, 19 Mar 2015 17:42:26 -0400 |
parents | 958307b30af3 |
children | b91356bf7186 |
files | hglib/util.py |
diffstat | 1 files changed, 4 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/hglib/util.py Mon Mar 16 17:59:27 2015 -0400 +++ b/hglib/util.py Thu Mar 19 17:42:26 2015 -0400 @@ -14,6 +14,10 @@ """Encode the string as bytes.""" return s +def strtobytes(s): + """Return the bytes of the string representation of an object.""" + return str(s).encode('latin-1') + def grouper(n, iterable): ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] ''' args = [iter(iterable)] * n