find the name of a csv file in python

To find the name of a CSV file in Python, you can use the pathlib module to get a Path object for the file. Then you can use string manipulation functions to extract the name of the file from the path.

Assuming the CSV file is in the current working directory, you can use the following code:

main.py
from pathlib import Path

# create a Path object for the CSV file
csv_file_path = Path("example.csv")

# get the file name (without extension)
csv_file_name = csv_file_path.stem

print(csv_file_name)  # prints "example"
220 chars
10 lines

If the CSV file is in a different directory, you can specify the full path when creating the Path object.

gistlibby LogSnag