kevin parks wrote:

I am kind of in a bit of a jam (okay a big jam) and i was hoping that someone here could give me a quick hand. I had a few pages of time calculations to do. So, i just started in on them typing them in my time calculator and writing them in by hand. Now i realize, that i really need a script to do this because: [...]

Ok, here you are. It isn't pretty, but it's the best I can do.

I would appreciate any comments regarding how it could be done better. Im just a newbie, learning how to program and Python at the same time...

BTW: This program doesn't save the result (could be solved by pickling the list?), or allow you to edit the records (re-use the last part of the code), and doesn't have item-tape awareness (so, if you make mistakes in start-end time, the program will never know). Also, the output is not like yours, because I have different print for each thing (make it only one print, add enough spacing and that's it)

HTH
Ismael

class Track:
def __init__(self, itemNumb, tapeNumb, trackNumb, startTime, endTime, comment):
self.itemNumb = itemNumb
self.tapeNumb = tapeNumb
self.trackNumb = trackNumb
self.startTime = startTime
self.endTime = endTime
self.comment = comment


def __repr__(self): ### This determines how the object reacts to "print object"
return str({"itemNumb":self.itemNumb, "tapeNumb":self.tapeNumb, "trackNumb":self.trackNumb, "startTime":self.startTime, "endTime":self.endTime, "comment":self.comment})


def time2sec(timeOrig):
   ''' Takes "min:sec" and converts it to seconds'''
   try:
       timeOrig = timeOrig.split(":")
       return int(timeOrig[0])*60+int(timeOrig[1])
   except IndexError:
       return "Error"
   except ValueError:
       return ""

def sec2time(timeOrig):
   ''' Takes "sec" and converts it to "min:sec"'''
   return str(timeOrig/60)+":"+str(timeOrig%60)

def getInput(inpType):
   if inpType == "integer":
       try:
           value = raw_input()
           value = int(value)
           return value
       except ValueError:
           if value == "": return "break"
           print "Value Erorr, type again"
           return None
   if inpType == "time":
       try:
           value = raw_input()
           if time2sec(value) == "Error":
               print "Format Error, type again"
               return None
           return value

except ValueError:
print "Value Erorr, type again"
return None


   if inpType == "time2":
       value = raw_input()
       if time2sec(value) == "Error":
           print "Format Error, type again"
           return None
       return value


i = 0 Tapes = []

print "Press ENTER on Item if you wish to finish"
while True:
   ### Inital values for each loop
   item = None
   tape = None
   track = None
   start = None
   end = None
   comment = None
   ###

   i = i+1

### Get everything
while item == None: print "Item_",
item = getInput("integer")
if item == "break": break


while tape == None:
print "TAPE_",
tape = getInput("integer")
while track == None:
print "Track:",
track = getInput("integer")


   while start == None:
       print "Start Time:",
       start = getInput("time")

   while end == None:
       print "End Time:",
       end = getInput("time2")

   comment = raw_input("Comment:")

   ###Fill it into the Tape object, into a list
   obj = Track(item, tape, track, start, end, comment)
   Tapes.append(obj)

print ""*2
print "Results:"
for i in range(len(Tapes)):
obj = Tapes[i]
start = time2sec(obj.startTime)
end = time2sec(obj.endTime)
if obj.endTime == "":
r = i while end == "":
r = r+1
obj2 = Tapes[r]
end = time2sec(obj2.startTime)
lenght = sec2time(end-start)
print "Item_", obj.itemNumb
print "TAPE_", obj.tapeNumb
print "Track:", obj.trackNumb
print "Start: 00:00"
print "End:", lenght
print "Comment:", obj.comment
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to