The Quine is a program, which takes no input, but it produces output. It will show it’s own source code. Additionally, Quine has some conditions. We cannot open the source code file inside the program.
a='a=%r;print (a%%a)';print (a%a)
a='a=%r;print (a%%a)';print (a%a)
Here a simple string formatting is working. We are defining a variable ‘a’, and inside a, we are storing ‘a=%r;print (a%%a)’ Then we are printing the value of a, and also replacing %r with the value of a. Thus the quine is working.
We can do the same task by opening the file like this.
print(open(__file__).read())
But in this case we are violating the rule of Quine. We cannot open file in Quine.