FULL ADDRESS OF MY CODES IN SOLOLEARN | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

21st Mar 2019, 4:37 AM
Saksham Jain
Saksham Jain - avatar
10 Answers
+ 5
handle=open(__file__,'r') I don't think Sololearn allows you to access other codes from a file
21st Mar 2019, 6:34 AM
Anna
Anna - avatar
+ 5
Ok .. Thanks Anna maybe I put __file__ in double quotes that's why not worked..
21st Mar 2019, 7:32 AM
Saksham Jain
Saksham Jain - avatar
+ 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..
21st Mar 2019, 5:02 AM
Saksham Jain
Saksham Jain - avatar
+ 4
Daljeet Singh Hope you find that code and update ..
21st Mar 2019, 6:49 AM
Saksham Jain
Saksham Jain - avatar
+ 4
Anna open(__file__,'r') not working
21st Mar 2019, 6:50 AM
Saksham Jain
Saksham Jain - avatar
+ 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
21st Mar 2019, 6:53 AM
Anna
Anna - avatar
+ 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
21st Mar 2019, 7:44 AM
Saksham Jain
Saksham Jain - avatar
+ 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 👍
21st Mar 2019, 4:59 AM
Daljeet Singh
Daljeet Singh - avatar
+ 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?
21st Mar 2019, 8:01 AM
KrOW
KrOW - avatar
+ 3
KrOW I just thought of it...I have no goal And I understand writing such files on SL server can be a security risk... I was just thinking about it no goal. Also if I write a file via python code as given above .Will that pollute SL Server?
21st Mar 2019, 8:23 AM
Saksham Jain
Saksham Jain - avatar