3

I wanted to know that how can we provide data while debugging in VS Code. For eg.

a = input()
b = input()

c = a + b

print(c)

I also have a input.txt file as follows:

10
20

So when I run python test.py < input.txt, the code should read the data and run.

But while debugging how can I tell the debugger to use the input?

2
  • Have you tried sys.argv[ ] method for reading the file? Commented Apr 14, 2019 at 12:18
  • sys.argv would require me to open file and read line by line. Isn't there something similar to just doing python test.py < input.txt while debugging? Commented Apr 14, 2019 at 12:58

1 Answer 1

1

Create a debugging configuration withexternalConsole": true. Check Igor's solution for more information. Reading input from a text file would not work for input() but instead you can provide as application parameters using sys.argv[].

screenshot of test code.

here is when I run the code with external debugging.

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.