Changeset 1947 for trunk/python
- Timestamp:
- 11/10/10 14:48:15 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r1938 r1947 725 725 return outvec 726 726 727 def _get_column(self, callback, row=-1 ):727 def _get_column(self, callback, row=-1, *args): 728 728 """ 729 729 """ 730 730 if row == -1: 731 return [callback(i ) for i in range(self.nrow())]731 return [callback(i, *args) for i in range(self.nrow())] 732 732 else: 733 733 if 0 <= row < self.nrow(): 734 return callback(row )735 736 737 def get_time(self, row=-1, asdatetime=False ):734 return callback(row, *args) 735 736 737 def get_time(self, row=-1, asdatetime=False, prec=0): 738 738 """\ 739 739 Get a list of time stamps for the observations. … … 747 747 asdatetime: return values as datetime objects rather than strings 748 748 749 """ 750 from time import strptime 749 prec: number of digits shown. Note this number is equals to 750 the digits of MVTime, i.e., 0<prec<3: dates with hh:: 751 only, <5: with hh:mm:, <7 or 0: with hh:mm:ss, 752 and 6> : with hh:mm:ss.tt... (prec-6 t's added) 753 754 """ 755 #from time import strptime 751 756 from datetime import datetime 752 times = self._get_column(self._gettime, row )757 times = self._get_column(self._gettime, row, prec) 753 758 if not asdatetime: 754 759 return times 755 format = "%Y/%m/%d/%H:%M:%S" 760 #format = "%Y/%m/%d/%H:%M:%S" 761 format = "%Y/%m/%d/%H:%M:%S.%f" 762 if prec < 7: 763 nsub = 1 + (((6-prec)/2) % 3) 764 substr = [".%f","%S","%M"] 765 for i in range(nsub): 766 format = format.replace(substr[i],"") 756 767 if isinstance(times, list): 757 return [datetime(*strptime(i, format)[:6]) for i in times] 758 else: 759 return datetime(*strptime(times, format)[:6]) 768 #return [datetime(*strptime(i, format)[:6]) for i in times] 769 return [datetime.strptime(i, format) for i in times] 770 else: 771 #return datetime(*strptime(times, format)[:6]) 772 return datetime.strptime(times, format) 760 773 761 774
Note:
See TracChangeset
for help on using the changeset viewer.