Best Python code snippet using slash
imdb.py
Source:imdb.py
...50 text = file.read()51 52 return text53 54 def _iter_path(self, path_list):55 data_dict = {'text': [], 'label': []}56 for path in path_list:57 content = self._read_txt(path)58 label = path.split('/')[-2]59 60 data_dict['text'].append(content)61 data_dict['label'].append(label)62 63 return data_dict64 65 @property66 def get_dict(self):67 """68 listing all path and read the file69 """70 train_pos = glob.glob(os.path.join(self.raw_folder, 'aclImdb', 'train', 'pos', '*'))71 train_neg = glob.glob(os.path.join(self.raw_folder, 'aclImdb', 'train', 'neg', '*'))72 test_pos = glob.glob(os.path.join(self.raw_folder, 'aclImdb', 'test', 'pos', '*'))73 test_neg = glob.glob(os.path.join(self.raw_folder, 'aclImdb', 'test', 'neg', '*'))74 75 data = self._iter_path(train_pos + train_neg + test_pos + test_neg)76 77 return data78 79 def split_dataset(self):80 """81 split data set into X_train, X_test, y_train, y_test82 """83 84 train_pos = glob.glob(os.path.join(self.raw_folder, 'aclImdb', 'train', 'pos', '*'))85 train_neg = glob.glob(os.path.join(self.raw_folder, 'aclImdb', 'train', 'neg', '*'))86 test_pos = glob.glob(os.path.join(self.raw_folder, 'aclImdb', 'test', 'pos', '*'))87 test_neg = glob.glob(os.path.join(self.raw_folder, 'aclImdb', 'test', 'neg', '*'))88 89 train = self._iter_path(train_pos+test_neg)90 X_train, y_train = train['text'], train['label']91 test = self._iter_path(train_neg+test_neg)92 X_test, y_test = test['text'], test['label']93 94 return X_train, X_test, y_train, y_tetst...
_playlist.py
Source:_playlist.py
...17 NOTE: 注ææä½åå·æ°ä¸ä¸ä¸ªææ¾18 æ ¹æ®è·¯å¾ï¼ç®å½ææ件ï¼æ·»å ææå¯ææ¾çæ件19 """2021 def _iter_path(path_index: pathlib.Path) -> set:22 result = []23 if not path_index.exists():24 pass25 elif path_index.is_file():26 need_append = path_index.resolve()27 result.append(need_append)28 elif path_index.is_dir():29 for i in path_index.iterdir():30 # éå½é²æ¢åºç°éç¯31 if i in self.searched_path:32 continue33 self.searched_path.append(path_index)34 result += _iter_path(i)35 return set(filter(self._is_media_file, result))3637 _path = pathlib.Path(path)38 if 'append' == operation:39 # 并é40 # self.file_list = set(self.file_list) | _iter_path(_path)41 self.file_list += [i for i in _iter_path(_path)42 if i not in self.file_list]43 if 'remove' == operation:44 # å·®é45 # self.file_list = set(self.file_list) - _iter_path(_path)46 self.file_list = [i for i in self.file_list47 if i not in _iter_path(_path)]48 return len(self.file_list)4950 def move_list(self, index, move_to_index):51 """52 NOTE: 注ææä½åå·æ°ä¸ä¸ä¸ªææ¾53 å° index 移å¨å° move_to_index54 ä¾å¦å [0,1,2,3,4,5] å° 1 移å¨å° 355 [0,2,1,3,4,5]56 """57 self.file_list.insert(move_to_index, self.file_list[index])58 if index > move_to_index:59 self.file_list.pop(index + 1)60 else:61 self.file_list.pop(index)
...
traverse.py
Source:traverse.py
...32 ['foo', 'bar', []]33 """34 if isinstance(path, list):35 return path36 def _iter_path(path):37 for parts in path.split('[]'):38 for part in parts.strip('.').split('.'):39 if part == '':40 continue41 yield part42 yield []...
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!!