Как "skaffman" сказал, используйте AOP, ИЛИ можно использовать переплетение байт-кода времени выполнения, точно так же, как инструменты покрытия метода модульного теста используют для прозрачного добавления информации о синхронизации к вызванным методам.
можно посмотреть на код, используемый инструментами инструментов с открытым исходным кодом как Emma ( http://downloads.sourceforge.net/emma/emma-2.0.5312-src.zip?modtime=1118607545&big_mirror=0 ). Другой инструмент покрытия с открытым исходным кодом http://prdownloads.sourceforge.net/cobertura/cobertura-1.9-src.zip?download .
, Если Вам в конечном счете удается сделать то, что Вы излагаете в. совместно используйте его назад с сообществом здесь с Вашей задачей Ant / банки.
На самом деле это почти то же самое в Python ..: -)
import datetime
year = datetime.date.today().year
Конечно, дата не связана со временем, поэтому, если это вам тоже небезразлично, вы можете сделать то же самое с полным объектом datetime:
import datetime
year = datetime.datetime.today().year
(Очевидно, что ничем не отличается, но вы, конечно, можете сохранить datetime.datetime.today () в переменной перед тем, как получить год).
Следует отметить один ключевой момент: компоненты времени могут различаться между 32-битными и 64-битными питонами в некоторых версиях Python (я думаю, дерево 2.5.x). Таким образом, на некоторых 64-битных платформах вы найдете такие вещи, как часы / минуты / секунды, а на 32-битных - часы / минуты / секунды.
import datetime
a = datetime.datetime.today().year
или даже (как Леннарт )
a = datetime.datetime.now().year
или даже
a = datetime.date.today().year
The other answers to this question seem to hit it spot on. Now how would you figure this out for yourself without stack overflow? Check out IPython, an interactive Python shell that has tab auto-complete.
> ipython
import Python 2.5 (r25:51908, Nov 6 2007, 16:54:01)
Type "copyright", "credits" or "license" for more information.
IPython 0.8.2.svn.r2750 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: import datetime
In [2]: now=datetime.datetime.now()
In [3]: now.
press tab a few times and you'll be prompted with the members of the "now" object:
now.__add__ now.__gt__ now.__radd__ now.__sub__ now.fromordinal now.microsecond now.second now.toordinal now.weekday
now.__class__ now.__hash__ now.__reduce__ now.astimezone now.fromtimestamp now.min now.strftime now.tzinfo now.year
now.__delattr__ now.__init__ now.__reduce_ex__ now.combine now.hour now.minute now.strptime now.tzname
now.__doc__ now.__le__ now.__repr__ now.ctime now.isocalendar now.month now.time now.utcfromtimestamp
now.__eq__ now.__lt__ now.__rsub__ now.date now.isoformat now.now now.timetuple now.utcnow
now.__ge__ now.__ne__ now.__setattr__ now.day now.isoweekday now.replace now.timetz now.utcoffset
now.__getattribute__ now.__new__ now.__str__ now.dst now.max now.resolution now.today now.utctimetuple
and you'll see that now.year is a member of the "now" object.