私はPythonとコーディング全般に不慣れです。各行にパス名を持つテキスト ファイルから読み込もうとしています。テキスト ファイルを 1 行ずつ読み取り、行の文字列をドライブ、パス、ファイル名に分割したいと思います。
これまでの私のコードは次のとおりです。
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
パスとファイル名のみが必要な場合、このエラーは表示されません。