Coverage for bzfs_main/utils.py: 100%
10 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-21 12:02 +0000
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-21 12:02 +0000
1#
2# Copyright 2024 Wolfgang Hoschek AT mac DOT com
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
16from typing import List, Optional
19def cut(field: int = -1, separator: str = "\t", lines: Optional[List[str]] = None) -> List[str]:
20 """Retains only column number 'field' in a list of TSV/CSV lines; Analog to Unix 'cut' CLI command."""
21 assert lines is not None
22 assert isinstance(lines, list)
23 assert len(separator) == 1
24 if field == 1:
25 return [line[0 : line.index(separator)] for line in lines]
26 elif field == 2:
27 return [line[line.index(separator) + 1 :] for line in lines]
28 else:
29 raise ValueError("Unsupported parameter value")