python-tutorial icon indicating copy to clipboard operation
python-tutorial copied to clipboard

Errors found in `functions_advanced`

Open edoardob90 opened this issue 8 months ago • 0 comments

There is a lingering datetime.utcnow() in the section about mutable objects as function's arguments:

from datetime import datetime

def log(msg, *, dt=datetime.utcnow()):
    print(f"{dt}: {msg}")

Should be:

from datetime import datetime, UTC


def log(msg, *, dt=datetime.now(UTC)):
    print(f"{dt}: {msg}")

edoardob90 avatar May 09 '25 08:05 edoardob90