0

In windows command line, I am using the redirection operator ("<") to read input from a file. To run my python module, I would do something like:

python myscript.py <input.txt

In myscript.py, I am using sys.stdin.readline() to read the input stream, something like:

def main(argv):
    line = sys.stdin.readline() 
    while line:
        doSomething()
        line = sys.stdin.readline()

if __name__ == "__main__": 
    main(sys.argv)

This works find on the command line.

Is there a way to use the redirection command in IPython? I want to debug the file. Thanks.

I am running Python 3.5.1:: Anaconda 2.5.0 on Win64.

1 Answer 1

1

Not easily. The redirection is a feature of the host command shell, and running anything inside IPython will isolate you from that.

Another way to do what you're looking for is to bring IPython into your program. If you know the place where it is breaking, you can add the following code to the except block of a try-except around the broken line:

import IPython
IPython.embed()

This will start an interactive IPython shell in the context the error occurred.

Alternatively, you can run the program under the control of the debugger: Step-by-step debugging with IPython

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.