0
void resetInput() {
    cin.clear();
    cin.ignore(numeric_limits<streamsize>::max(), '\n'); //discard input
}

The above code method is to reset inputs. I'm looking for a way to convert this into the Python method. Can someone please help me to do it?

  • 2
    This calls C++ specific API which do not have equivalent in python. Your code do not have enough context to do this conversion. – Marek R May 27 '21 at 13:04
  • When an I/O error occurs in Python, it **raises** an `OSError` (IOError is an alias to OSError, these days). There is no "error state" to clear. Python's I/O stream's `readline` can be used to read-and-discard a line. – Eljay May 27 '21 at 13:06
  • @Eljay this function is not for IO specific errors. This is used for handling errors when for example user type a word when program expected a number. Without knowing how he reads data from stdin in python code you can't tell what should be done. – Marek R May 27 '21 at 13:08
  • I think this question is already answered here: https://stackoverflow.com/questions/2520893/how-to-flush-the-input-stream-in-python – Paul Bryan May 27 '21 at 13:12

0 Answers0