Best Python code snippet using ATX
task_9.py
Source:task_9.py
...22 method = None23 while method not in self.METHODS:24 method = input(f'ÐведиÑе меÑод [{self.METHODS}]: ').strip().lower()25 return method26 def _input_keyboard(self):27 self.a = input('ÐведиÑе ÑÑÑаÑегии игÑока A: ').strip().split()28 self.b = input('ÐведиÑе ÑÑÑаÑегии игÑока B: ').strip().split()29 m = []30 for i in range(len(self.a)):31 while True:32 row = input(f'ÐведиÑе {i} ÑÑÑока [{len(self.b)} ÑиÑел]: ').strip().split()33 if len(row) != len(self.b):34 print(f'ТÑебÑеÑÑÑ {len(self.b)} ÑиÑел')35 if all(map(lambda s: self.FLOAT__PATTERN.match(s), row)):36 row = list(map(float, row))37 break38 m.append(row)39 self.m = np.array(m)40 def _input_random(self):41 while True:42 a_len = input('ÐведиÑе колиÑеÑÑво ÑÑÑаÑегий игÑока Ð: ').strip()43 if a_len.isdigit():44 a_len = int(a_len)45 break46 while True:47 b_len = input('ÐведиÑе колиÑеÑÑво ÑÑÑаÑегий игÑока B: ').strip()48 if b_len.isdigit():49 b_len = int(b_len)50 break51 self.a = list(map(str, range(a_len)))52 self.b = list(map(str, range(b_len)))53 self.m = np.random.randint(0, 1e5, (a_len, b_len))54 def _input_csv(self):55 data = pd.read_csv('../data/task_9/strategies.csv')56 self.a = data['name'].tolist()57 self.b = data.columns.tolist()[1:]58 self.m = data.drop(['name'], axis=1).to_numpy()59 def input(self, default: bool = False):60 method = self._input_method()61 if method == 'keyboard':62 self._input_keyboard()63 elif method == 'random':64 self._input_random()65 elif method == 'csv':66 self._input_csv()67 def output(self):68 print(f'ÐпÑималÑÐ½Ð°Ñ ÑиÑÑÐ°Ñ ÑÑÑаÑÐµÐ³Ð¸Ñ Ð´Ð»Ñ Ð¸Ð³Ñока Ð: {self.a_win}', end='\n\n')69 print(f'Цена игÑÑ Ð´Ð»Ñ Ð¸Ð³Ñока РпÑи вÑбоÑе ÑиÑÑой опÑималÑной ÑÑÑаÑегии: {self.a_price}', end='\n\n')70 print(f'ÐпÑималÑÐ½Ð°Ñ ÑиÑÑÐ°Ñ ÑÑÑаÑÐµÐ³Ð¸Ñ Ð´Ð»Ñ Ð¸Ð³Ñока B: {self.b_win}', end='\n\n')71 print(f'Цена игÑÑ Ð´Ð»Ñ Ð¸Ð³Ñока B пÑи вÑбоÑе ÑиÑÑой опÑималÑной ÑÑÑаÑегии: {self.b_price}', end='\n\n')72 print('ТаблиÑа ÑмеÑаннÑÑ
ÑÑÑаÑегий Ð´Ð»Ñ Ð¸Ð³Ñока Ð')73 print(pd.DataFrame([self.a_mixed_win], columns=self.a).to_string(index=False), end='\n\n')74 print(f'Цена игÑÑ Ð´Ð»Ñ Ð¸Ð³Ñока РпÑи вÑбоÑе ÑмеÑанной опÑималÑной ÑÑÑаÑегии: {self.a_mixed_price}', end='\n\n')75 print('ТаблиÑа ÑмеÑаннÑÑ
ÑÑÑаÑегий Ð´Ð»Ñ Ð¸Ð³Ñока B')76 print(pd.DataFrame([self.b_mixed_win], columns=self.b).to_string(index=False), end='\n\n')...
keyboard.py
Source:keyboard.py
1import ctypes, time2VK_LBUTTON = 0x13VK_RBUTTON = 0x24VK_CANCEL = 0x35VK_MBUTTON = 0x46VK_BACK = 0x87VK_TAB = 0x98VK_CLEAR = 0x0C 9VK_RETURN = 0x0D 10VK_SHIFT = 0x1011VK_SHF = VK_SHIFT12VK_CONTROL = 0x1113VK_CTRL = VK_CONTROL14VK_CTL = VK_CONTROL15VK_MENU = 0x1216VK_ALT = VK_MENU17VK_PAUSE = 0x1318VK_CAPITAL = 0x1419VK_ESCAPE = 0x1B 20VK_SPACE = 0x2021VK_PRIOR = 0x2122VK_NEXT = 0x2223VK_END = 0x2324VK_HOME = 0x2425VK_LEFT = 0x2526VK_UP = 0x2627VK_RIGHT = 0x2728VK_DOWN = 0x2829VK_SELECT = 0x2930VK_PRINT = 0x2A 31VK_EXECUTE = 0x2B 32VK_SNAPSHOT = 0x2C 33VK_INSERT = 0x2D 34VK_DELETE = 0x2E 35VK_HELP = 0x2F 36VK_0 = 0x3037VK_1 = 0x3138VK_2 = 0x3239VK_3 = 0x3340VK_4 = 0x3441VK_5 = 0x3542VK_6 = 0x3643VK_7 = 0x3744VK_8 = 0x3845VK_9 = 0x3946VK_A = 0x4147VK_B = 0x4248VK_C = 0x4349VK_D = 0x4450VK_E = 0x4551VK_F = 0x4652VK_G = 0x4753VK_H = 0x4854VK_I = 0x4955VK_J = 0x4A 56VK_K = 0x4B 57VK_L = 0x4C 58VK_M = 0x4D 59VK_N = 0x4E 60VK_O = 0x4F 61VK_P = 0x5062VK_Q = 0x5163VK_R = 0x5264VK_S = 0x5365VK_T = 0x5466VK_U = 0x5567VK_V = 0x5668VK_W = 0x5769VK_X = 0x5870VK_Y = 0x5971VK_Z = 0x5A 72VK_NUMPAD0 = 0x6073VK_NUMPAD1 = 0x6174VK_NUMPAD2 = 0x6275VK_NUMPAD3 = 0x6376VK_NUMPAD4 = 0x6477VK_NUMPAD5 = 0x6578VK_NUMPAD6 = 0x6679VK_NUMPAD7 = 0x6780VK_NUMPAD8 = 0x6881VK_NUMPAD9 = 0x6982VK_SEPARATOR = 0x6C 83VK_SUBTRACT = 0x6D 84VK_DECIMAL = 0x6E 85VK_DIVIDE = 0x6F 86VK_F1 = 0x7087VK_F2 = 0x7188VK_F3 = 0x7289VK_F4 = 0x7390VK_F5 = 0x7491VK_F6 = 0x7592VK_F7 = 0x7693VK_F8 = 0x7794VK_F9 = 0x7895VK_F10 = 0x7996VK_F11 = 0x7A 97VK_F12 = 0x7B 98VK_F13 = 0x7C 99VK_F14 = 0x7D 100VK_F15 = 0x7E 101VK_F16 = 0x7F 102VK_F17 = 0x80103VK_F18 = 0x81104VK_F19 = 0x82105VK_F20 = 0x83106VK_F21 = 0x84107VK_F22 = 0x85108VK_F23 = 0x86109VK_F24 = 0x87110VK_NUMLOCK = 0x90111VK_SCROLL = 0x91112VK_LSHIFT = 0xA0 113VK_RSHIFT = 0xA1 114VK_LCONTROL = 0xA2 115VK_RCONTROL = 0xA3 116VK_LMENU = 0xA4 117VK_RMENU = 0xA5 118VK_PLAY = 0xFA 119VK_ZOOM = 0xFB 120_WORD = ctypes.c_ushort121_DWORD = ctypes.c_ulong122_LONG = ctypes.c_long123_ULONG_PTR = ctypes.POINTER(_DWORD)124_KEYEVENTF_EXTENDEDKEY = 0x0001125_KEYEVENTF_KEYUP = 0x0002126_KEYEVENTF_SCANCODE = 0x0008127_KEYEVENTF_UNICODE = 0x0004128_INPUT_MOUSE = 0129_INPUT_KEYBOARD = 1130_INPUT_HARDWARD = 2131class _MOUSEINPUT(ctypes.Structure):132 _fields_ = (('dx', _LONG),133 ('dy', _LONG),134 ('mouseData', _DWORD),135 ('dwFlags', _DWORD),136 ('time', _DWORD),137 ('dwExtraInfo', _ULONG_PTR))138class _HARDWAREINPUT(ctypes.Structure):139 _fields_ = (('uMsg', _DWORD),140 ('wParamL', _WORD),141 ('wParamH', _WORD))142class _KEYBDINPUT(ctypes.Structure):143 _fields_ = (("wVk", _WORD), 144 ("wScan", _WORD),145 ("dwFlags", _DWORD),146 ("time", _DWORD), 147 ("dwExtraInfo", _ULONG_PTR))148class _INPUTUNION(ctypes.Union):149 _fields_ = (('mi', _MOUSEINPUT),150 ('ki', _KEYBDINPUT),151 ('hi', _HARDWAREINPUT))152class _INPUT(ctypes.Structure):153 _fields_ = (('type', _DWORD),154 ('union', _INPUTUNION))155def _sendModifiers(mods, press):156 if mods & 0x01:157 _sendVirtual(0x10, press)158 if mods & 0x02:159 _sendVirtual(0x11, press)160 if mods & 0x04:161 _sendVirtual(0x12, press)162def _sendVirtual(vk, press=True):163 keybdinput =_KEYBDINPUT(vk, ctypes.windll.user32.MapVirtualKeyA(vk, 0), 0 if press else _KEYEVENTF_KEYUP)164 input = _INPUT(_INPUT_KEYBOARD, _INPUTUNION(ki=keybdinput))165 ctypes.windll.user32.SendInput(1, ctypes.byref(input), ctypes.sizeof(input))166def _sendScanCode(scanCode, press=True):167 scanned = ctypes.windll.user32.VkKeyScanA(ord(scanCode))168 vk = scanned & 0xff169 modifiers = scanned >> 8170 if press and modifiers: _sendModifiers(modifiers, True)171 _sendVirtual(vk, press)172 if not press and modifiers: _sendModifiers(modifiers, False)173def _sendTokens(tokens, press=True):174 vks = []175 for token in tokens.upper().split():176 try:177 vk = globals()['VK_'+token] 178 except:179 raise Exception("no virtual key [VK_]%s" % token)180 vks.append(vk)181 if not press: vks.reverse()182 for vk in vks:183 _sendVirtual(vk, press)184def _send(key, press=True):185 if isinstance(key, int):186 return _sendVirtual(key, press)187 188 if isinstance(key, str):189 n = len(key)190 if n==1:191 return _sendScanCode(key, press)192 if n>1:193 return _sendTokens(key, press)194 195 raise Exception("unsupported key %s" % key)196def click(c, delay=0.05):197 _send(c, True)198 if delay>0:199 time.sleep(delay)200 _send(c, False)201def press(c):202 _send(c, True)203def release(c):204 _send(c, False)205 206def isDown(c):207 return bool(ctypes.windll.user32.GetKeyState(c) & 0x8000) 208def isToggled(c):...
test_windows.py
Source:test_windows.py
...2324# def drag(self):25# pass2627# def _input_keyboard(self, text):28# pass293031def _test():32 try:33 name = u"Windows ä»»å¡ç®¡çå¨"34 win = FrozenWindow(name.encode("gbk"), exclude_border=True)35 win.set_foreground()36 time.sleep(0.1)37 win._screenshot('taskman-pil.png')38 time.sleep(0.5)39 win._screenshot_cv2('taskman-cv2.png')40 except Exception as e:41 print str(e)
...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!