# Spoof file list used to demonstrate file io fileList = ["aiwydgawd_20130105_142354.dat", "fseawfaiwydgawd_20130205_745632.dat", "aiwydgwfafaawd_20120525_123456.dat", "aawfiwydgawd_20110613_987321.dat", "aiwyfwaafdgawd_20121225_123456.dat", "aiwydgawhersfad_20100105_147963.dat"] # Spoof associative array used to demonstrate string lookups dialogApps = {"142354":"Bills", "745632":"Letters", "123456":"Junk", "987321":"Summons", "147963":"Credit"} """Provides polling functionality""" class FilePoller(object): """Static method takes a file list and returns an array of jobs""" @staticmethod def Poll(fileList): jobs = [] # Iterate over the files collection and construct a "Job" instance for each for file in fileList: jobs.append(Job(file)) return jobs """Provides functionality to invoke Dialog on a remote server, lol""" class InvokeDialog(object): """Static method spoofs the process of adding a job to the Dialogue database""" @staticmethod def AddToDB(job): print "The following details have been added to the Dialogue database:" print job """Encapsulates the parameters which define a Job""" class Job(object): filename = "" application = "" dateStamp = "" """Default constructor takes a filename, and parses the properties""" def __init__(self,filename): self.filename = filename self.application = dialogApps[filename.split("_")[2][:6]] self.dateStamp = filename.split("_")[1] """Overridden method returns the string representation of this job object""" def __repr__(self): return ', '.join("%s: %s" % item for item in vars(self).items()) + "\n" # Run those jobs! RUN THEM GOOD. for job in FilePoller.Poll(fileList): InvokeDialog.AddToDB(job)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question