简体   繁体   中英

getting an error "not defined" trying to Path(file.csv) in python

I am learning to use the Path tool to import .CSV files in python. I have saved a .CSV file in the same location as the .PY file. here is my code:

from pathlib import Path

csvpath = Path(data_test.csv)

print (csvpath)

The error message is saying: "NameError: name "data_test" is not defined"

what is going on here? the .CSV and .PY files are in the same location. ??

the path should be a string csvpath = Path('data_test.csv')

print (csvpath)

It cant find it, because its looking for a declared variable data_test.csv

from pathlib import Path
csvpath = Path("data_test.csv")  # filename should be inside " "
print (csvpath)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM