Explain this line of code.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Explain this line of code..

#input print(open(__file__).read()) #output is same how? #print(open(__file__).read())

1st Sep 2018, 10:42 AM
Meet Rajpopat
Meet Rajpopat - avatar
2 Answers
+ 9
__file__ is the name Python gives to the current .py script being executed. What you are doing is essentially opening the file that is being run, reading it and printing it. Here's a silly code I wrote to have a bit of fun with that 😎 https://code.sololearn.com/cyVMX5BsatD7/?ref=app
1st Sep 2018, 10:57 AM
David Ashton
David Ashton - avatar
0
David Ashton can you explain in simple language please,i found it complicated
6th Sep 2018, 1:14 PM
Meet Rajpopat
Meet Rajpopat - avatar