d = dir(datetime.datetime.now())
for i in d:
if not i.startswith('_'): # Skip private members
m = getattr(datetime.datetime.now(), i) # Get the method
print i, # Print the name
try: # some will not work without more info or at all.
print m()
except Exception, e:
print e
應該給你一個好的開始。在Python 2.6上面的代碼給出了:
astimezone Required argument 'tz' (pos 1) not found
combine Required argument 'date' (pos 1) not found
ctime Mon Nov 25 13:23:18 2013
date 2013-11-25
day 'int' object is not callable
dst None
fromordinal fromordinal() takes exactly 1 argument (0 given)
fromtimestamp Required argument 'timestamp' (pos 1) not found
hour 'int' object is not callable
isocalendar (2013, 48, 1)
isoformat 2013-11-25T13:23:18.190000
isoweekday 1
max 'datetime.datetime' object is not callable
microsecond 'int' object is not callable
min 'datetime.datetime' object is not callable
minute 'int' object is not callable
month 'int' object is not callable
now 2013-11-25 13:23:18.195000
replace 2013-11-25 13:23:18.195000
resolution 'datetime.timedelta' object is not callable
second 'int' object is not callable
strftime Required argument 'format' (pos 1) not found
strptime strptime() takes exactly 2 arguments (0 given)
time 13:23:18.198000
timetuple time.struct_time(tm_year=2013, tm_mon=11, tm_mday=25, tm_hour=13, tm_min=23, tm_sec=18, tm_wday=0, tm_yday=329, tm_isdst=-1)
timetz 13:23:18.199000
today 2013-11-25 13:23:18.199000
toordinal 735197
tzinfo 'NoneType' object is not callable
tzname None
utcfromtimestamp utcfromtimestamp() takes exactly 1 argument (0 given)
utcnow 2013-11-25 13:23:18.202000
utcoffset None
utctimetuple time.struct_time(tm_year=2013, tm_mon=11, tm_mday=25, tm_hour=13, tm_min=23, tm_sec=18, tm_wday=0, tm_yday=329, tm_isdst=0)
weekday 0
year 'int' object is not callable
對於日期時間由'dir'顯示的各種方法總的來說對於格式沒有任何作用。 –