+ 18
[Assignment] Hack SL's Python input()
Here is the idea : Before this week's contest, I thought it was impossible to use multiline (with undefined number of line) input() in the codeplayground with Python. It appeared to be actually possible, using fileinput module, or as well using while + yield. https://code.sololearn.com/ch2Mx7bv1Svo/#py https://code.sololearn.com/cQ50qDt88Q34/#py I know it's certainly more complicated ( but there are so many skilled pythonists on SL ), my idea is : let's try to find a way for a CodePlayground python code to accept (and ask for) a 'later' input, one that would, many time if needed, ask for input during its execution. This possibility would add so much interactivity to our codes here !
18 ответов
+ 13
Python Persistance solved here (Well done Kirk !):
https://www.sololearn.com/Discuss/1387409/solved-python-sololearn-database-access
+ 11
And what about exporting some data on the web (github account for instance) at each execution and retrieve/modify it during next executions. I'm not used to this kind of functions with python, but there must be ... ?
+ 10
tamaslud
Ok !
Any idea how to do that technically ?
+ 10
So here is what I understand:
Our python codes are named "source.py".
They are trapped in the middle of controlled pipes on windows servers.
Input is controlled by an application that sends it to our code threw a pipe after we wrote it.
Codes are given a limited amount of time(around 5 sec) and memory (around 1Mo) to be executed.
During this time, they can read data from web locations with urllib.
But any module that could help to WRITE something remotely is not installed.
They can create files in their own directory, these files will be deleted immediately after execution. They can't create any directory, or files elsewhere.
A 'later' input is not possible in these conditions, sure, but we are here to find a sideway.
A nice hack would be for codes to be able to write some retrievable memory, any kind. Something to store data that could be used during a later execution.
I'm naive in this field, so I have no clue how to do it, but here is my idea:
When a SL CP python code requests data from an url, doesn't the requested server recieve an information ? Isn't that request traceable ?
If so : what we need is a server hosting a dedicated program that could recognize those requests and their content (I don't know what is the content of a requests but there must be some), and store some data that could be fetched during a later execution ...
Correct me if I'm wrong somewhere, and tell me if you have more elements : )
+ 10
KrOW has written a great solution for Html/CSS/JS codes.
It uses another Html/CSS/JS code as a Json. Works great, he posted it here, you can try it !
Will someone find a way to do a similar trick with other languages ?
It seems possible with python but KrOW told me he gets an access error on his https request. I've read that urllib should be able to do it, but I'm not skilled enough ... Someone ?
+ 9
Dmitriy
That's the answer I already saw many times, and well, maybe you're right.
But I also have this experience of situations when everybody keeps repeating that something is impossible, until someone comes with a different perspective ...
+ 5
Some people use heredocs to simulate multiline input via a text / iostream (""" docstrings """ are good for this because they retain newlines)
When thinking about interactivity, it may help to consider what's attached to stdin/stdout at the run location:
https://code.sololearn.com/cG2HfDHa9WGx/?ref=app
+ 5
i must note that i am a beginner pythonist. this input restrictions limit the possibilities to create a really interactive code.
as i understand the sl server runs the full code in the backround and the result (in a time limit) is displayed for the user. it is possible to ask the user to hit the run button again and again, but generally it is not possibly to inherit a variable from a previous run. i think this later thing would be hacked somehow. i try to work it out.
+ 4
it's not impossible yo make interactive programm on SL, overwize in web, because web app will run in your browser, not in SL playground
+ 3
my idea is to somehow have an external counter registering the serial number of code executions. e.g.:
execution1: prints 'enter input1'
ex2: input1 then do something with input1, prints 'enter input2'
ex3: input2 etc.
the code needs to be executed again and again, but remembers the number of executions and maybe some previous inputs.
so the code needs to access to an external file.
+ 3
tamaslud as i said previously, everything is executed server side and all variables are temporary and stored only during one code execution, so without actually breaching SL servers it isn't possible to save a variable anywhere.
+ 3
hinanawi i understand. but i think variables are stored at some physical place, and if the garbage collector doesn't replace it by nulls immediately after run, and this place is addressable somehow from sl terminal it would mean a solution.
+ 3
tamaslud if the SL devs are any smart, they remove all values after code execution from their database, because i can see it getting clogged up easily if they don't. and even if they don't, there most likely isn't a way to access anything from the code playground
+ 2
tamaslud there's no way to force the code to execute itself again, because that's done on SL's server side of things. but the concept is really interesting.
+ 1
not possible during execution, because the SL compiler is server-side and it only sends the request for input to your browser/app once
+ 1
If you want store something on SL code, i have maded this
https://code.sololearn.com/WlKZDLTpM7jZ/?ref=app
+ 1
Cépagrave On SL i cannot make https requests then i cannot make request to SL thats need for make it work