2024-12-14, 11:18
Hier ein paar Beispiele, wie man mit icecream print() Ausgaben ersetzen kann.
"""
icecream examples
"""
from icecream import ic
# define some function
def addiere(x, y):
return x + y
# call ice
ic(addiere(1, 2))
# Output:
# ic| addiere(1, 2): 3
d = {'i': 2, 'j': 3, 'k': 4711}
ic(d['k'])
struct = {
"hersteller": "VW",
"modell": "Golf",
"Farben": ["gelb", "rot"]
}
ic(struct)
ic.disable()
ic(struct) # no output
ic.enable()
def logstuff(text):
# log to output file
print(text)
ic.configureOutput(prefix="Hallo| ", outputFunction=logstuff)
ic(addiere(7, 7))
ic.configureOutput(prefix="Welt| ", outputFunction=logstuff)
ic(addiere(7, 7)) |
"""
icecream examples
"""
from icecream import ic
# define some function
def addiere(x, y):
return x + y
# call ice
ic(addiere(1, 2))
# Output:
# ic| addiere(1, 2): 3
d = {'i': 2, 'j': 3, 'k': 4711}
ic(d['k'])
struct = {
"hersteller": "VW",
"modell": "Golf",
"Farben": ["gelb", "rot"]
}
ic(struct)
ic.disable()
ic(struct) # no output
ic.enable()
def logstuff(text):
# log to output file
print(text)
ic.configureOutput(prefix="Hallo| ", outputFunction=logstuff)
ic(addiere(7, 7))
ic.configureOutput(prefix="Welt| ", outputFunction=logstuff)
ic(addiere(7, 7))
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website