Monthly Archives: May 2016

Python locale error: unsupported locale setting

Sometimes we are getting local error and cannot install packages via pip.

I found a solution to get rid of it.

Run this command from your command line interface.

$ export LC_ALL=C

Output from locale is:

$ locale
LANG=co404
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=C

Get the date n days ago and n days after in Python

Few day’s ago I found a helpful method to get n day’s ago date and n days after date from current date. Following functions are written based on Python 3.

Date n day’s ago:


from datetime import datetime, timedelta

def get_n_days_before_date(date_format="%d %B %Y", days_before=120):

    date_n_days_ago = datetime.now() - timedelta(days=days_before)
    return date_n_days_ago.strftime(date_format)

Date n day’s after:

from datetime import datetime, timedelta

def get_n_days_after_date(date_format="%d %B %Y", add_days=120):

    date_n_days_after = datetime.now() + timedelta(days=add_days)
    return date_n_days_after.strftime(date_format)