This continues my last post.
So, say you want to write a console program that collects user information to populate the fields of a spreadsheet, i.e. provide the attribute data for the instance of a class. Here are some thoughts I had starting out.
There is a class Project, which – for the time being – has attributes Title and Location. In my first version I wanted to do this.
def __init__(self, Title, Location)
self.Title = Title
self.Location = Location
Title = raw_input(“Enter Project Title: “)
Location = raw_input(“Enter Project Location: “)
newproject = PROJECT(Title, Location)
That was straight forward. But I was going to need this same routine for many more attributes, not only for PROJECT but even more attributes for the borehole class (POINT). Plus, I wanted to include a routine, e.g. dataEntry(), that would allow me to change any one attribute after creating the instance. So how about:
def dataEntry(Title, Location):
self.Title = raw_input(“Enter Project Title: “)
self.Location = raw_input(“Enter Project Location: “)
newproject = PROJECT()
This seems cleaner to me. The program part only instantiates and then calls the method. The rest of code is in the class. One reason I didn’t like the gINT interface is because I had to always enter the same information over and over again. Some things never changes, some things didn’t change during the project but had to be entered 50 times for 50 boreholes. So assigning some attributes default values in def __init__ (those that never change) and then starting the dataEntry routine for attributes that change, makes the most sense to me. So for example:
def __init__(self, ProjectTitle=“New Title”, Driller=“New Driller”, DrillRig=“New DrillRig”):
def dataEntry(self, Depth, Date):
self.Depth = raw_input(“Enter BoreHole Depth: “)
self.Date= raw_input(“Enter Date Drilled: “)
newBorehole = Borehole()
What this does is instantiate the class Borehole, using dafault values for Title, Driller, Drillrig (which remain the same for all borehole instances) and then prompt for borehole specific input…. TO BE CONTINUED