I have written simple decorator which prints the function passed to it (for example "foo"), and then I decorate it against itself. So finally it prints both written functions.
I have read about quines recently and a little bit stuck with its a precise definition. For example, according to this source a quine "must print out precisely those instructions which the programmer wrote as part of the program".
So my question is: Can I consider the written program as a quine?
def decorate(function):
from inspect import getsourcelines
def wrapper(*args, **kwargs):
for line_num, code_line in enumerate(getsourcelines(function)[0]):
print(code_line)
return wrapper
@decorate
def foo(bar1, bar2=777):
print("bar")
foo(None)
decorate(decorate)(decorate)
precise output is:
@decorate
def foo(bar1, bar2=777):
print("bar")
def decorate(function):
from inspect import getsourcelines
def wrapper(*args, **kwargs):
for line_num, code_line in enumerate(getsourcelines(function)[0]):
code_line = code_line.replace('\n', '')
print(code_line)
return wrapper