maxempoint / AR_GBX

Python Framework for interacting with the Action Replay GBX
GNU General Public License v3.0
0 stars 1 forks source link

Use Path instead of string for file name references #17

Open philippfriese opened 2 years ago

philippfriese commented 2 years ago

Python 3 offers the module pathlib, which provides the class Path. A path object encapsulates either a system file or directory and is transparent to the operating system.

A Path object overloads the division operator / and allows for the following path operations:

from pathlib import Path

dir_path = Path("directory")
my_file_path = dir_path / "myfile.txt"

On POSIX systems, / with correctly concatenate the directory and filename with a slash. On Windows, the back slash is used instead. Almost all standard libraries support Path objects. For those calls not supporting it, the Path object can be converted back to a string e.g. using str(my_file_path).

Recommendation: Use pathlib to improve cross-platform support and ease working with paths.