Skip to content

Instantly share code, notes, and snippets.

@devilgate
devilgate / banner.py
Last active January 25, 2019 10:22
A simple Python routine to present a string in a banner-style box of asterisks
def banner(text, width=40):
"""Print the received text in a banner-style box"""
STARS = "".center(width, "*")
BLANK = "{}{}{}".format("*", "".center(width - 2), "*", )
usable_text_length = width - 4
print()
print(STARS)
print(BLANK)
@devilgate
devilgate / backupfile.py
Last active January 31, 2019 15:42
Creating a temporary or backup file in Python
import time
from pathlib import Path
def create_backup_file(file):
"""Create a timestamped, uniquely-named backup version of the received
file
"""
while True:
backup_file_name = "{}.{}.bak".format(file.name,