+5

[SOLVED] Loading own modules in code playground

I am playing around with creating modules and am wondering if there is anyway to use code bits as modules in the SL environment. I figured out how to import modules with pip, but I want to experiment writing my own modules. I hacked some code to simulate the scenario of loading a module I created, but it kind of defeats the purpose because the code is just a multi-line string being wrote to a file and then imported?! I could just make it a function at that point?! [code removed]

4/3/2020 12:23:23 AM

Code Crasher

14 Answers

New Answer

+2

Simply, you can't. Because sololearn's code playground doesn't save anything in its directory at all. Even if we try to damage the the system nothing will happen to it. It's memory is fully temporary. However you can do something like this with web scraping. Check out this code as an example: https://code.sololearn.com/cLZWa86IxxQR/?ref=app

+4

You can't import your code bits in SoloLearn code playground as modules. But you can practice that with a local Python IDE.

+4

Code Crasher Nicely done, BTW isn't that going to take like a whole lots of code accompanying a slow execution in the main thread since sololearn forces the if __name__ = "__main__" Statement to always return True.....I'd be glad at a solution that shows the exact location of the code bits so "__import__('sys').append(path)" will work

+3

i am pretty positive code playground is a container and the webserver is an entirely different environment, that is launching the containers. I don't know for sure, but I plan to look at the page source to look at the elements to see if I can find something. I am sure it is getting called from storage behind the webserver and isnt directly accessible, but it cant hurt to look?

+3

BTW: For those responding or viewing this thread... there is no need for negative votes. I had a sincere question, so I asked it. I understand the Moderators response, so my post needed some adjusting... that is fine. There is no need for down-voting anything unless someone starts spamming this thread. I am learning and exploring, so join me and respond, but there is no need to be negative. Depending on what I find, I will likely send an email to info@SoloLearn.com, so if you have a solution or wish to have similar functionality in code playground, add constructive comments and we can make this platform better for everyone. Happy Coding!

+2

Code Crasher Nope, bs4 does the ascii stuffs automatically. Just the html source code looks different. Even the emojis appear correctly.

+2

Pluto |^_^| https://code.sololearn.com/c6xo6t8IvUoW I got it working (sort of)! 😎 I will play with it later to see how I want to incorporate it. 👍

+1

Mirielle(20k XP Monthly till November [2020]) the code I posted is a hack and not the way I want to do it. Requesting from url might work, but it would require parsing a web page on the SL web server? That is not ideal either. I was wondering if there is another url that has just the code that the playground loads from. I doubt it, because it is probably a security issue, but that was my initial thought. It is an honest question and not show casing the mess of code I pieced together to get it to work. Gordon that was my assumption, but I was hoping there was a way. I am using VSCode to do what I want, but I thought it would be cool to share the concept with those at a similar level as I am, without hacking together extra code to add complexity, that might confuse users that have not tried it yet. I am going to research further, but I was hoping someone who has been here longer, had a solution.

+1

Code Crasher i get you... That will be easy if you know the directory of where the code bit was saved...I don't think there's a chance for that

+1

Pluto |^_^| yep. I discovered some cool open source JS stuff while investigating the page, but it does look like they are doing things on the back end that prevent what I want to do. 😞 Web scraping is the last resort, but I have a few projects that do this, so I know it is doable... it looks like either parsing the 'window.code' variable or the 'saveSourceCode' form input field will get the code, but there are ASCII codes that will need to be converted for it to work. Finding an ASCII dictionary to look up against iterating through the scrape text will probably be the easiest way to do it. However I am going to look at bs4 to see if it can do it automagically. I haven't given up on trying to pass something to the JS yet either... I just have to find more time to play. I am also still trying to look for old posts to see if anybody has even tried to do what I'm trying to do before I email a feature suggestion to SL. 👍

+1

Pluto |^_^| nice. probably try it tomorrow. 👍

+1

Mirielle yep, this is why I dont like doing it the way it is going, but it turned into, "can it be done?" rather than "is it productive?". Most of the code I write right now is inefficient and just mashed together as I learn, and I totally realize that, but that is the reason we do it in environments like this, instead of out in the real world?! 😉 Thanks for reinforcing my thoughts, and giving me some specifics on "why" I haven't really thought of yet. You have no idea how much I appreciate the Mods and more experienced developers on SL. It really has made this learning experience quicker than I anticipated, and has jump started and stretched my goals on projects a lot further than if I were to study outside of SL. Thank you for the feedback. Always Grateful!!! 😎👍 "You don't learn to walk by following rules. You learn by doing, and by falling over." --Richard Branson

+1

Pluto |^_^| got the write in the right path finally. I had to do some nosing around, but I got it working. 😎👍 [EDIT: Lol! I just looked at Coding Einstein code again ... talk about "reinventing the wheel?" The first time thru I was too impatient to try to follow it. Kinda glad it happened that way though. I learned some cool stuff and found a like-mind to follow I think?! 😜] I am going to check out the urlopen() you suggested and see if I can trim everything up into a smaller cut and paste. 😉 it's a hack, from a beginner, but it works!!! I am calling it a success. ✅ Thanks everyone for the feedback and motivating me to write some more code... I need the practice! 🍻 Happy Coding!

0

Are you having any problem with your code ? If YES : then specify the problem Else this isn't the right place to showcase your code...the method provided isn't new and has been in used for long... The new method we should be expecting now is how to load module from other code's url without using ```import urllib.request```