Skip to content

Commit 8a423d2

Browse files
committed
use pathlib operations where possible
1 parent d34b07a commit 8a423d2

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

tfs/tools.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@
88
from __future__ import annotations
99

1010
import logging
11-
from typing import TYPE_CHECKING
11+
from pathlib import Path
1212

1313
import numpy as np
1414

1515
from tfs.errors import TfsFormatError
1616
from tfs.reader import read_tfs
1717
from tfs.writer import write_tfs
1818

19-
if TYPE_CHECKING:
20-
from pathlib import Path
21-
2219
LOGGER = logging.getLogger(__name__)
2320

2421

@@ -88,8 +85,7 @@ def remove_header_comments_from_files(list_of_files: list[str | Path]) -> None:
8885
"""
8986
for filepath in list_of_files:
9087
LOGGER.info(f"Checking file: {filepath}")
91-
with open(filepath) as f:
92-
f_lines = f.readlines()
88+
f_lines = Path(filepath).read_text().splitlines(keepends=True)
9389

9490
delete_indicies = []
9591
for index, line in enumerate(f_lines):
@@ -104,5 +100,4 @@ def remove_header_comments_from_files(list_of_files: list[str | Path]) -> None:
104100
deleted_line = f_lines.pop(index)
105101
LOGGER.info(f" Deleted line: {deleted_line.strip():s}")
106102

107-
with open(filepath, "w") as f:
108-
f.writelines(f_lines)
103+
Path(filepath).write_text("".join(f_lines))

tfs/writer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import string
1313
from types import NoneType
1414
from typing import TYPE_CHECKING
15+
1516
import numpy as np
1617
from pandas.api import types as pdtypes
1718
from pandas.io.common import get_handle

0 commit comments

Comments
 (0)