2023-03-22

Is there a way to make a python script output itself when compiled?

I have an arbitrary program that needs to output itself when compiled to bytecode/exe, although it doesn't need to be a quine that contains itself.

I tried having it access itself through open(__file__, 'rt'), but this doesn't work when it is compiled to bytecode.

An example program is this:

import random
if 1 == random.randint(0,1):
    print(source code)

The program prints the source code 50% of the time. What could I add in the print statement?



No comments:

Post a Comment