-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Function to easily convert relative to abs path
- Loading branch information
1 parent
3a8932e
commit 655822c
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from pathlib import Path #to work with relative paths | ||
|
||
## Function to convert a relative path to absolute path | ||
def rel2abs(relative_path: str) -> str: | ||
''' | ||
Convert a relative path to an absolute path. | ||
Parameters: | ||
- relative_path (str): The relative path to be converted. | ||
Returns: | ||
- str: The absolute path. | ||
Example: | ||
``` | ||
relative_path = 'subfolder/file.txt' | ||
absolute_path = rel2abs(relative_path) | ||
``` | ||
''' | ||
# Get the absolute path | ||
absolute_path = Path(relative_path).resolve() | ||
|
||
# Convert Path object to string | ||
return str(absolute_path) |