Data Entry Routine (for gINT) using Python Code

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.


class PROJECT:

    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:


class PROJECT:
     def __init__(self):
     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:


class Borehole:
     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



Filed under Uncategorized

2 responses to “Data Entry Routine (for gINT) using Python Code

  1. Pingback: Instance Inheritance – Python (My Project Cont’d) « Adventures in GIS

  2. Pingback: Python – Populate Class from TXT File « Arne's Adventures in GIS

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s