From b47b4393288199967bdffc082703f01e09e704a6 Mon Sep 17 00:00:00 2001 From: Debasish Pradhan Date: Sat, 6 Jun 2026 11:03:30 +0530 Subject: [PATCH] Check if 'foo.txt' exists before setting data_path Add file existence check before defining data_path. --- Article/PythonBasis/python18/1.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Article/PythonBasis/python18/1.md b/Article/PythonBasis/python18/1.md index af1d7b9a..d78e4fd7 100644 --- a/Article/PythonBasis/python18/1.md +++ b/Article/PythonBasis/python18/1.md @@ -96,9 +96,12 @@ print(data_path) ```python from pathlib import Path +import os -base = Path('/tmp') -data_path = base / 'demo' / 'sub' / 'foo.txt' +file_exist = os.path.isfile('foo.txt') +if file_exist: + base = Path('/tmp') + data_path = base / 'demo' / 'sub' / 'foo.txt' print(data_path) ```