Lesson 44 / 49
datetime, os & sys
Work with dates, times and time differences using datetime, and use os and sys for files and arguments.
datetime basics
datetime handles dates, times and the difference between two moments.
from datetime import datetime, timedelta
now = datetime.now()
print(now.strftime("%Y-%m-%d %H:%M"))
tomorrow = now + timedelta(days=1)
print(tomorrow.date())os & sys
os interacts with the filesystem and environment; sys exposes interpreter-level details like command-line arguments.
import os, sys
print(os.getcwd()) # current working directory
print(os.listdir(".")) # files in this folder
print(sys.argv) # command-line arguments
print(sys.version_info) # interpreter version