repack是一组著名的python实用程序,它们很好地打包在一起。
Repack的Python项目详细描述
欢迎重新包装!
repack是一组著名的实用程序,它们被很好地打包在一起。 为了说明这个想法,想象一下,您需要通过url查询传递一个对象 字符串,重新打包后,它看起来像:
import repack token1 = (repack .json_encode() .bytify() .deflate() .base64_encode() .url_encode() .converter() .send({'id': 10001, 'desc':'this is a token' }))
但通常情况下,您会这样做:
import json import zlib import base64 import urllib.parse string = json.dumps({'id': 10001, 'desc':'this is a token' }) stream = bytes(string, 'utf-8') stream = zlib.compress(stream) string = base64.b64encode(stream) token1 = urllib.parse.quote(string)
感觉不同:)你也希望它是Lasy,这样你就可以做一个转换器 一次以后使用:
urlit = (repack .json_encode() .bytify() .deflate() .base64_encode() .url_encode() .converter())
像这样:
token1 = urlit.send({'id': 10001, 'desc':'this is a token' })
或者像这样:
token2 = urlit.send('another token lol') token3 = urlit.send('one more yay') token4 = urlit.send('yay!!!')
您可以将实用程序链接为filter,也就是说,值解释为False
。
不会通过:
with (repack .reverse() .printout() .filter()) as f: f.send('olleH') f.send(None) f.send('!dlroW') f.send(None)
打印:
Hello World!
另一个例子是迭代器,它允许以后设置源代码:
with (repack .trim() .integer() .iterator()) as iterator: results = [] for v in iterator.send(iter(['1 ','\t2', '\n3'])): results.append(v)
结果:
[1, 2, 3]
反之亦然,使用累加器:
with (repack .trim() .integer() .accumulator()) as acc: acc.send('1 ') acc.send('\t2') acc.send('\n3') results = [] for v in acc: results.append(v)
该软件包正在开发中。欢迎大家投稿。 对于todo,请查看根文件夹中的当前todo列表。
要求
- python 3.4.2
安装
sudo pip install repack
延伸
就像在filters/__init__.py
或更多流中添加更多过滤器一样简单
到flows/__init__.py
。