home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Python 1.3 / source code / Demo / sgi / cd / listcd.py < prev    next >
Encoding:
Text File  |  1995-12-17  |  428 b   |  25 lines  |  [TEXT/R*ch]

  1. # List track info from CD player.
  2.  
  3. import cd
  4.  
  5. def main():
  6.     c = cd.open()
  7.     info = []
  8.     while 1:
  9.         try:
  10.             info.append(c.gettrackinfo(len(info) + 1))
  11.         except RuntimeError:
  12.             break
  13.     for i in range(len(info)):
  14.         start, total = info[i]
  15.         print 'Track', zfill(i+1), triple(start), triple(total)
  16.  
  17. def triple((a, b, c)):
  18.     return zfill(a) + ':' + zfill(b) + ':' + zfill(c)
  19.  
  20. def zfill(n):
  21.     s = `n`
  22.     return '0' * (2 - len(s)) + s
  23.  
  24. main()
  25.