tgoop.com/pythonpool/273
Create:
Last Update:
Last Update:
⚠️ Daily Python Facts ⚠️
An elegant way to deal with a file path (3.4≥)>>> from pathlib import Path
>>> data_folder = Path("source_data/text_files/")
# Path calculation and metadata
>>> file_to_open = data_folder / "raw_data.txt"
>>> file_to_open.name
"raw_data.txt"
>>> file_to_open.suffix
"txt"
>>>file_to_open.stem
"raw_data"
# Files functions
>>> f = open(file_to_open)
>>> f.read()
# content of the file
>>> file_to_open.exists()
True
- @pythonpool -
BY Python Pool | Python Course | Machine Learning | Data Science Tutorials | Artificial Intelligence | Computer Science Programming
Share with your friend now:
tgoop.com/pythonpool/273