def run(self): allFiles = gameEngine.getAllFiles("games") all_files_size = allFiles.__len__() if all_files_size == 0: print("No games downloaded yet!") else : i = 0 for file in allFiles: i += 1 print("{0} {1}".format(i, file)) while True: try: mode = int(input("Input:")) except ValueError: # just catch the exceptions you know! print ('That\'s not a number!') else: if 1 <= mode < all_files_size + 1: # this is faster break else: print ('Out of range. Try again') cwd = os.getcwd() os.chdir(cwd + "/games") os.system("cls") with open(allFiles[mode-1]) as python_file: code = compile(python_file.read(), python_file, 'exec') exec(code) os.chdir(cwd) input("Press any key to restart!") os.system("cls")
def run(self): print("Name of game") print(self.directory) print("================") allFiles = gameEngine.getAllFiles("games", self.directory) all_files_size = allFiles.__len__() if all_files_size == 0: print("No games downloaded yet!") else: i = 0 for file in allFiles: i += 1 print("{0} {1}".format(i, file)) while True: try: data, addr = server.sock.recvfrom(40) server.ch.check_if_here(addr) data = data.decode() if data: try: mode = int(data) except ValueError: pass else: if 1 <= mode < all_files_size + 1: break else: pass except OSError: sys.exit() os.chdir(self.directory + "/games") os.system("clear") with open(allFiles[mode-1]) as python_file: code = compile(python_file.read(), python_file, 'exec') exec(code) os.chdir(self.directory) del sys.path[1] while True: try: data, addr = server.sock.recvfrom(40) server.ch.check_if_here(addr) data = data.decode() if data: break except OSError: sys.exit() os.system("clear")