๐Ÿ“– Beginning Python Programming /
Module: Defining Functions

Using datetime module & functions

๐Ÿ“– Beginning Python Programming / Defining Functions / Using datetime module & functions

Code Example: Utils module

'''Define some helper functions.'''

def today():
    '''Return today's date in YYYY-MM-DD.'''
    import datetime
    return str(datetime.date.today())

def download_file(url):
    '''Download file from particular URL.'''
    from urllib.request import urlretrieve

    filename = url.split('/')[-1]
    urlretrieve(url, filename)

Usage 1

from utils import today, download_file

download_file('https://makzan.net/resume.pdf')

print( f'today is {today()}' )

Usage 2

import utils

utils.download_file('https://makzan.net/resume.pdf')

print( f'today is {utils.today()}' )