Собрали в одном месте самые важные ссылки
читайте нас в Telegram
>>> from flags import Flags
>>> class TextStyle(Flags):
>>> bold = 1 # value = 1 << 0
>>> italic = 2 # value = 1 << 1
>>> underline = 4 # value = 1 << 2
>>> result = TextStyle.bold | TextStyle.italic
>>>
>>> print(result)
TextStyle(bold|italic)
>>> print(repr(result))
<TextStyle(bold|italic) bits=0x0003>
Страшный проект, который, по словам авторов, позволяет начать экономить память при использовании в нейронных сетях и deep learning
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import print_function from dataIO import js from dataIO import pk from dataIO import textfile data = {"name": "John", "age": 18, "favorite number": 3.1415926535, "hobby": ["Music", "Sport"]} js.safe_dump(data, "data.json", indent_format=True, float_precision=2, enable_verbose=True) pk.safe_dump(data, "data.pickle", enable_verbose=True) s = "This\nis\nPython!" textfile.write(s, "text.txt")
>>> from natsort import natsorted
>>> a = ['a2', 'a9', 'a1', 'a4', 'a10']
>>> natsorted(a)
['a1', 'a2', 'a4', 'a9', 'a10']
$ cat /tmp/data | histogram.py --percentage --max=1000 --min=0
# NumSamples = 60; Min = 0.00; Max = 1000.00
# 1 value outside of min/max
# Mean = 332.666667; Variance = 471056.055556; SD = 686.335236; Median 191.000000
# each ∎ represents a count of 1
0.0000 - 100.0000 [ 28]: ∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎ (46.67%)
100.0000 - 200.0000 [ 2]: ∎∎ (3.33%)
200.0000 - 300.0000 [ 2]: ∎∎ (3.33%)
300.0000 - 400.0000 [ 8]: ∎∎∎∎∎∎∎∎ (13.33%)
400.0000 - 500.0000 [ 8]: ∎∎∎∎∎∎∎∎ (13.33%)
500.0000 - 600.0000 [ 7]: ∎∎∎∎∎∎∎ (11.67%)
600.0000 - 700.0000 [ 3]: ∎∎∎ (5.00%)
700.0000 - 800.0000 [ 0]: (0.00%)
800.0000 - 900.0000 [ 1]: ∎ (1.67%)
900.0000 - 1000.0000 [ 0]: (0.00%)
import sys
import time
import daemonocle
# This is your daemon. It sleeps, and then sleeps again.
def main():
while True:
time.sleep(10)
if __name__ == '__main__':
daemon = daemonocle.Daemon(
worker=main,
pidfile='/var/run/daemonocle_example.pid',
)
daemon.do_action(sys.argv[1])