Uncatchable error with empty stdin input


If the input box for python stdin is empty, the error

 Error: Command failed: timeout 7 python3 HelloWorld.py 

is thrown and cannot be caught using a try: except: statement. I think it should either throw a catchable error or return null (preferably return null).

I may as well be missing something and there is a way to make input optional in which case I would appreciate your answers.

Edit: is there a dedicated place to report bugs like this? If so, let me know

3 Answers

3 years ago by

Hello, Yes you can definitely report the bugs here.
Your program is timing because you are probably using input but not providing the STDIN (in the textarea)

Currently we do not have any recommonded solutions for optional inputs. Can you please add NA in STDIN if you do not want to pass any inputs?

3 years ago by Divya

I just came across a solution online. The condition

 if select.select([sys.stdin,],[],[],0.0)[0]:

from the module select checks if the user has given input to stdin. Using that I am now able to simply set a default value in the else statement.
Here is a function that takes the input and returns a null object if there is none:

 def readLine():
    if select.select([sys.stdin,],[],[],0.0)[0]: return sys.stdin.readline()
    return None
3 years ago by dot

def fibonacci_till_num(last_num):
a, b = 0, 1
while a <= last_num:
print(a, end=' ')
a, b = b, a+b

number = int(input('please enter one natural number: '))
fibonacci_till_num(number)

1 year ago by Thummala Bhargavi