Rositsa Zlateva
Full Stack Python Developer and lecturer
def sum_number_digits(number):
print(number)
digits = []
for ch in str(number):
print(ch)
print(type(ch))
digits.append(ch)
print(digits)
return sum(digits)
print(sum_number_digits(45))
print(sum_number_digits('4O'))
import logging
logging.basicConfig(
filename='example.log',
level=logging.DEBUG,
format='%(asctime)s:%(levelname)s:%(message)s'
)
def sum_number_digits(number):
logging.debug(number)
digits = []
for ch in str(number):
logging.debug(ch)
logging.debug(type(ch))
digits.append(ch)
logging.debug(digits)
return sum(digits)
print(sum_number_digits(45))
print(sum_number_digits('4O'))
2021-03-14 22:47:12,091:DEBUG:45
2021-03-14 22:47:12,091:DEBUG:4
2021-03-14 22:47:12,091:DEBUG:<class 'str'>
2021-03-14 22:47:12,091:DEBUG:5
2021-03-14 22:47:12,091:DEBUG:<class 'str'>
2021-03-14 22:47:12,091:DEBUG:['4', '5']
logger.add("out.log", backtrace=True, diagnose=True)
def func(a, b):
return a / b
def nested(c):
try:
func(5, c)
except ZeroDivisionError:
logger.exception("What?!")
nested(0)
Loguru example
2018-07-17 01:38:43.975 | ERROR | __main__:nested:10 - What?!
Traceback (most recent call last):
File "test.py", line 12, in <module>
nested(0)
└ <function nested at 0x7f5c755322f0>
> File "test.py", line 8, in nested
func(5, c)
│ └ 0
└ <function func at 0x7f5c79fc2e18>
File "test.py", line 4, in func
return a / b
│ └ 0
└ 5
ZeroDivisionError: division by zero
pdb - https://docs.python.org/3/library/pdb.html
pdb++ - https://github.com/pdbpp/pdbpp
IPython pdb - https://github.com/gotcha/ipdb
hunter - https://github.com/ionelmc/python-hunter
Total number of calls
primitive calls
ncalls
tottime
percall
cumtime
percall #2
filename:lineno
SnakeViz example
& useful links
LinkedIn - https://www.linkedin.com/in/rositsa-kotseva/
GitHub - https://github.com/rositsazz
By Rositsa Zlateva