How to fix Python error “AttributeError: ‘datetime.datetime’ object has no attribute ‘timestamp'”

Problem:

You want to convert a datetime object into a unix timestamp ( int or float : seconds since 1970-1-1 00:00:00 ) in Python using code like

from datetime import datetime
timestamp = datetime.now().timestamp()

but you see an error message like this:

Traceback (most recent call last):
  File "unix-timestamp.py", line 2, in <module>
    timestamp = datetime.now().timestamp()