Last active
June 22, 2018 23:44
-
-
Save wings27/a7ffc67657d902e77f7d3ff688728efc to your computer and use it in GitHub Desktop.
python equivalent for Scanner in java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Scanner: | |
def __init__(self): | |
self.__line_split = None | |
self.__pointer = None | |
def next_int(self): | |
try: | |
next_str = self._next_str() | |
ret = int(next_str) | |
return ret | |
except ValueError: | |
return None | |
def _next_str(self): | |
if not self.__line_split or self.__pointer >= len(self.__line_split): | |
self.__line_split = self.__next_line_str().split() | |
self.__pointer = 0 | |
if not self.__line_split: | |
return '' | |
next_one = self.__line_split[self.__pointer] | |
self.__pointer += 1 | |
return str(next_one) | |
def __next_line_str(self): | |
self.__line_split = None | |
self.__pointer = None | |
line = str(raw_input()) | |
return line | |
def main(): | |
scanner = Scanner() | |
while True: | |
n = scanner.next_int() | |
if n is None: | |
break | |
# todo: insert code here | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment