Skip to content

Instantly share code, notes, and snippets.

View jorge-lavin's full-sized avatar
🏠
Working from home

Jorge Lavin jorge-lavin

🏠
Working from home
View GitHub Profile
import string
def validate(fqdn):
"""docstring for validate"""
valid_chars = list(string.ascii_letters + string.digits + '-' + '.')
if all(char in valid_chars for char in fqdn):
return True
else:
return False
import csv
with open('datos.csv') as fichero_de_datos:
reader = csv.reader(fichero_de_datos, delimiter=';')
for lines in reader:
print [ items for items in lines if items != '' ]
import os
import logging
import logging.config
'''
If you try to log to a non existing folder, this shows how an IOError exception is raised. The non existing folder may be /logs in current working directory.
IMPORTANT: This assumes a logging.ini configuration file for the logging exists with a log_file_path variable pointing at the file to be logged at.
The contents of logging.ini are:
"""
Taken from http://www.jeffknupp.com/blog/2013/04/07/improve-your-python-yield-and-generators-explained/
Just added a python2 check
"""
import sys
if sys.version[0] == '2':
print('This code is not Python 2 compliant exiting ...')
exit(0)
def file_to_string(file_path):
"""
Converts a file into a string. \\t\\n join is used for format purposes in Outlook
"""
with open(file_path) as file_:
reader = csv.reader(file_, delimiter=';')
#If no delimiter is specified and are commas, ;, or other csv reader delimiters, this function may not
#work as expected. Therefore we force it to have ; because are not likely to be present
line = []
for lines in reader:
#Python 2
python -m SimpleHTTPServer 8080
#Python 3
python3 -m http.server 8113
# Code taken from http://codereview.stackexchange.com/a/61539/52090
import sys
exit_codes = [
(ValueError, 10),
(KeyError, 25)
]
# now you can also use a dictionary here, but
# Slightly adapted from http://www.artima.com/weblogs/viewpost.jsp?thread=240808
# Tested under Python 2.6.6, 3.4.1
def entryExit(f):
"""
This decorator adds the funcionality defined in new_f()
"""
def new_f():
"""
from __future__ import print_function # only for module main() test function
import csv
import sys
PY3 = sys.version_info[0] > 2
def read_properties(filename, delimiter=':'):
''' Reads a given properties file with each line of the format key=value.
Returns a dictionary containing the pairs.
filename -- the name of the file to be read
'''