0

I'm trying to override the standard raw_input so I can have a "remote raw_input".

What I need is to implement this overriden raw_input so when I use it on my server, it will open a message box in the remote client's computer and wait for his answer. After getting the response, I'll then be able to continue with my program.

I've been searching a lot about how I can do this, but I'm a little lost mostly because I'm new to python.

And I have to do this with raw_input, is that possible? Can someone give me a little guidance?

UPDATE:

One good example of what I'm trying to achieve is how Jupyter handles raw_inputs.

In this notebook I simply run a raw_input, then Jupyter creates a textbox and waits for my answer:

Jupyter textbox

And then after I type my answer it goes on with the code:

Jupyter textbox2

So how does Jupyter get 'in the middle' of the raw_input to create a textbox and wait for the user input?

1 Answer 1

0

Overriding builtins is, generally, not recommended for a number of reasons. Instead, try something like the following, using receive_input instead of raw_input.

SERVER = 1
CLI    = 2
...
config.input_type = CLI # in cli code, or SERVER in server code
...
def receive_input(cfg):
    if cfg.input_type == CLI:
        return raw_input()
    elif cfg.input_type == SERVER:
        # retrieve from somewhere else

Jupyter likely scans the AST of the input for raw_input called as a function and replaces that with their implementation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.