我是 python 和一般编码的新手。我正在尝试从每行都有路径名的文本文件中读取。我想逐行读取文本文件并将行字符串拆分为驱动器、路径和文件名。
到目前为止,这是我的代码:
import os,sys, arcpy
## Open the file with read only permit
f = open('C:/Users/visc/scratch/scratch_child/test.txt')
for line in f:
(drive,path,file) = os.path.split(line)
print line.strip()
#arcpy.AddMessage (line.strip())
print('Drive is %s Path is %s and file is %s' % (drive, path, file))
我收到以下错误:
File "C:/Users/visc/scratch/simple.py", line 14, in <module>
(drive,path,file) = os.path.split(line)
ValueError: need more than 2 values to unpack
当我只需要路径和文件名时,我没有收到此错误。