آموزش itertools: groupby پشتسرهم #پایتون
pythonhost.ir | پایتون هاست
@pythonhost_ir
import itertools
s = 'aaabcc'
print([(k, len(list(g))) for k, g in itertools.groupby(s)])
pythonhost.ir | پایتون هاست
@pythonhost_ir
آموزش argparse مینیمال #پایتون
pythonhost.ir | پایتون هاست
@pythonhost_ir
import argparse
p = argparse.ArgumentParser()
p.add_argument('--n', type=int, default=3)
args = p.parse_args([])
print(args.n)
pythonhost.ir | پایتون هاست
@pythonhost_ir
آموزش logging با فرمت #پایتون
pythonhost.ir | پایتون هاست
@pythonhost_ir
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s')
logging.info('ready')
pythonhost.ir | پایتون هاست
@pythonhost_ir
آموزش traceback تمیز #پایتون
pythonhost.ir | پایتون هاست
@pythonhost_ir
import traceback
try:
1 / 0
except ZeroDivisionError:
print(traceback.format_exc().splitlines()[-1])
pythonhost.ir | پایتون هاست
@pythonhost_ir