Python3 cheatsheet
get current encoding
code:
import sys
print(sys.stdout.encoding)
example output:
UTF-8
parsing a (german) date
code:
from datetime import datetime
date = '24.11.1986 03:07:00'
date_standard = datetime.strptime(date, '%d.%m.%Y %H:%M:%S')
print(date_standard)
example output:
1986-11-24 03:07:00
formating a date to a german date
code:
from datetime import datetime
date = '1986-11-24 03:07:00'
date_formated = date_standard.strftime('%d.%m.%Y um %H:%M Uhr')
print(date_formated)
example output:
24.11.1986 um 03:07 Uhr
getting the PID of current script
code:
import os
thisScriptPid = str(os.getpid())
print(thisScriptPid)
example output:
9112