TheShed

Python DateTime

Category: Programming
#Python #Dates

A fragment for formatting dates and time in Python:

import datetime
date = datetime.datetime.now()
sDate = date.strftime("%Y%m%d")
sDateTime =  date.strftime("%Y%m%d %H:%M:%S")

See see https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior for formatting for details of string formatting for dates and times.

Python Command Line Arguments

Category: Programming
#Python #fragments

A fragment for processing arguments passed from the command line:

import sys
#… stuff
myArg = sys.argv[1]         # argv[0] is the name of the command

For more sophisticated parsing, StackOverflow has recommendations.