Last active
May 10, 2021 17:55
-
-
Save RackReaver/234eb69e512231a105b8f95859ccd8b4 to your computer and use it in GitHub Desktop.
python snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def append_csv(filename, value): | |
"""This will append a vaule to a csv file. | |
args: | |
filename (str): full path or relative path of the csv file. | |
value (str): string to append to the csv file. | |
Return: None | |
""" | |
with open(filename, 'a') as openFile: | |
openFile.write('\n{}'.format(value)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import logging | |
def log_config(): | |
# Logging configuration | |
fmtstr = "%(asctime)s: %(levelname)s - %(message)s" | |
logging.basicConfig( | |
filename='tracking.log', | |
level=logging.INFO, | |
filemode='a', | |
format=fmtstr | |
) | |
# Log when script runs with machine name and script name | |
logging.info('{} started {}'.format( | |
socket.gethostname(), os.path.basename(__file__))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
def read_csv(filename): | |
"""This will import single column csv files. | |
args: | |
filename (str): full path or relative path of the csv file. | |
Return (list): list of row values in the csv file. | |
""" | |
final_list = [] | |
with open(filename, 'r') as openFile: | |
reader = csv.reader(openFile) | |
for row in reader: | |
final_list.append(row[0]) | |
return final_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
today = datetime.now() | |
plus_days = 7 | |
final_date = today + timedelta(days=int(plus_days)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment