TransWikia.com

How can I show the code of my program in the output in python?

Stack Overflow Asked by Ayaan Singh Saundh on December 7, 2021

I’m a beginner python coder and I am currently using eclipse IDE to code.I want to display the code of my program in my program itself. Is there any way to do so?

2 Answers

You can use Python string escaping, string literal generation & unescaping. Paste your own code in here: https://www.pythonescaper.com/

And you can print escaped string;

print("Past here escaped string")

Answered by user11247496 on December 7, 2021

In your script, use this. This will read the file and display it's contents

print(open(__file__).read())

Answered by bigbounty on December 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP