Skip to content

Handle paths using Pathlib and/or os.path.join #18

Open
@luisaforozco

Description

@luisaforozco

Since GL is a package that is going to be used by users in different platforms i.e. windows, linux, macOS, it is necessary that the paths will be platform independent. Currently GL works in macOS and linux but it wouldn't in windows, where the paths are with single or double \ instead of /.

To solve this I propose:

use pathlib:

from pathlib import Path
data_folder = Path("source_data/text_files/")
file_to_open = data_folder / "raw_data.txt"

# It also works concatenating multiple strings on the fly:
>>> a_string = "path/to/something"
>>> a_path = Path(a_string+"/new/directory/type")
PosixPath('path/to/something/new/directory/type')

# and adding a str to a Path
>>> a_path / "new/string/path"
PosixPath('path/to/something/new/directory/type/new/string/path')

and/or also use os.path.join

import os
data_folder = os.path.join("source_data", "text_files")
file_to_open = os.path.join(data_folder, "raw_data.txt")

# This also works concatenating a string and a pathlib Path
>>> ab = Path("test/one")
>>> os.path.join(ab,"other/test/")
'test/one/other/test/'

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions