Skip to content

Instantly share code, notes, and snippets.

@sanfx sanfx/
Created Oct 12, 2013

What would you like to do?
This script is for purpose to explain how logging works as well how mox testing done; see
import sys
import ast
import logging
class ItemNotString(Exception):
class FilterList(object):
""" docstring for FilterList
def __init__(self, filterby):
super(FilterList, self).__init__()
self._filter = filterby
def stringListItems(self, lst):
for index, item in enumerate(lst):
if type(item) == str:
raise ItemNotString("%i item '%s' is not of type string" % (index+1, item))
return True
def filterList(self, lst):
if self.stringListItems(lst):
if not self._filter:"Nothing passed to filter list %s" % lst)
filteredList = []
for eachItem in lst:
if eachItem.startswith(self._filter):
if filteredList == []:"The list %s doesn't have any matching string item starting with letter '%s'." %(lst, self._filter))
return filteredList
if __name__ == "__main__":
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
# logging.basicConfig(filename='myapp.log', level=logging.INFO)
filterby = sys.argv[2]
except IndexError:
filterby = None
flObj = FilterList(filterby)
result = flObj.filterList(ast.literal_eval(sys.argv[1]))
if result:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.