Skip to content

Commit

Permalink
Add more types of path manipulations to python activity
Browse files Browse the repository at this point in the history
  • Loading branch information
k-dominik committed May 28, 2024
1 parent 82e50b8 commit b3179f1
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions _includes/string_concat/manipulating_file_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,24 @@
# Combine folder and file name.
# pathlib.Path objects support "syntactic sugar", like using '/' as a
# separator when composing paths.
path = tmp_folder / file_name
print(path)
image_path = tmp_folder / file_name
print(image_path)

# %%
# The parent for a Path object gives you the containing folder
parent_folder = image_path.parent
print(parent_folder == tmp_folder)

# %%
# Let's create a file name for a label image derived from the nuclei.tif
# such the file name will be nuclei_labels.tif.
filename_no_extension = image_path.stem
print(filename_no_extension)
labels_path = tmp_folder / f"{filename_no_extension}_labels.tif"

# %%
# Now we want to create a file name for a .csv file, that shares the
# file name up to the extension.
# If we only change the extension, we can use the with_suffix method.
csv_path = image_path.with_suffix(".csv")
print(csv_path)

0 comments on commit b3179f1

Please sign in to comment.