How to use _iter_path method in Slash

Best Python code snippet using slash

imdb.py

Source:imdb.py Github

copy

Full Screen

...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...

Full Screen

Full Screen

_playlist.py

Source:_playlist.py Github

copy

Full Screen

...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) ...

Full Screen

Full Screen

traverse.py

Source:traverse.py Github

copy

Full Screen

...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 []...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful