无法打印文件

时间:2016-04-10 02:01:05

标签: python list

我在打印这个城市列表时遇到问题,这是我正在使用的代码

更新:我已插入

print(repr(folderpath))

这是我得到的错误

Traceback (most recent call last):
File "C:/Users/Michaelf/Desktop/GEOG M173/week_2_Lab.py", line 72, in <module>
citylist = os.listdir(folderpath + "\NA_Cities.dbf")
WindowsError: [Error 267] The directory name is invalid: 'C:\\Users\\Michaelf\\Desktop\\Test_Folder\\LabData\\NA_Cities.dbf/*.*'
  
    
      

    
  
citylist = os.listdir(folderpath + "\NA_Cities.dbf")
print citylist

这是我得到的错误

Traceback (most recent call last):
 File "C:/Users/Michaelf/Desktop/GEOG M173/week_2_Lab.py", line 71, in <module>
citylist = os.listdir(folderpath + "\NA_Cities.dbf")
WindowsError: [Error 267] The directory name is invalid: 'C:\\Users\\Michaelf\\Desktop\\Test_Folder\\LabData\\NA_Cities.dbf/*.*'

1 个答案:

答案 0 :(得分:0)

NA_Cities.dbf看起来像文件名而不是目录。 os.listdir将返回目录中的所有文件。请尝试使用open(os.path.join(folderpath, 'NA_Cities.dbf')),请参阅open