+ 4
FULL ADDRESS OF MY CODES IN SOLOLEARN
Suppose i have a code which prints itself ... How can i access my code files using a program .. in this program i want i to print itself but file does not exist so i need full address of my code... https://code.sololearn.com/cpCA3T1h9Kiy/?ref=app
10 ответов
+ 5
handle=open(__file__,'r')
I don't think Sololearn allows you to access other codes from a file
+ 5
Ok .. Thanks Anna maybe I put __file__ in double quotes that's why not worked..
+ 4
Daljeet Singh Please elaborate..And also how do I access my some other code on sololearn from this code...I need to know the full address of my codes..
+ 4
Daljeet Singh Hope you find that code and update ..
+ 4
Anna open(__file__,'r') not working
+ 4
Saksham Jain Well, it works for me. Replace the first line with handle=open(__file__,'r') and it prints the content of the file
+ 4
Hey I created a new code...
Anna Daljeet Singh
I want to know where is my new file is created and saved...
It should have been saved in the same directory as my code but I don't see it in code playground...
https://code.sololearn.com/cbR06LPwP0nU/?ref=app
+ 3
print self.. :
one way is use 'source.py'
edit :
Saksham Jain
playground doesn't allow you to access root directory
and full address of code you already have
another way is :
import inspect
def sl(x):
y = 9
return x+y
print(inspect.getsource(sl))
edit : although I have seen one user's code actually printing recently ran codes @ playground which I can't find at present if found will update 👍
+ 3
Saksham Jain I dont think than SL built the system to get easy access to them local files... It could be a security problem/risk. Futhermore your codes are supposed to be showed only throught the SL service and not directly throught a direct access...Anyway why you need of these adress? What is your last goal?