Skip to content

Instantly share code, notes, and snippets.

@Joshuaalbert
Created February 6, 2017 13:21
Show Gist options
  • Select an option

  • Save Joshuaalbert/af44cb3628719d4790f775b7a33bb377 to your computer and use it in GitHub Desktop.

Select an option

Save Joshuaalbert/af44cb3628719d4790f775b7a33bb377 to your computer and use it in GitHub Desktop.
import dill
from sys import stdout
class Logger(object):
def __init__(self,logFile=None,standardOut = True):
if standardOut:
self.file = [stdout]
else:
self.file = []
if logFile is not None:
try:
file = open(logFile,"w")
self.file.append(file)
except:
print("Failed to open log file {0}".format(logFile))
if len(self.file) == 0:
print("No logger files!")
exit(1)
#print("Using log files: {}".format(self.file))
def __exit__(self):
for file in self.file:
try:
file.close()
except:
pass
def log(self,message,endLine=True):
for f in self.file:
if endLine:
f.write("{0}\n".format(message))
else:
f.write("{0}".format(message))
f.flush()
class RadioArray(object):
def __init__(self,log = None):
if log is None:
logger = Logger()
self.log = logger.log
def PrepareData():
dataFile = 'DillPickleBug_data'
print("creating radio array")
radioArray = RadioArray()
dataDict = {'radioArray':radioArray}
f = open(dataFile,'wb')
dill.dump(dataDict,f)
f.close()
return
if __name__ == '__main__':
PrepareData()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment