我正在尝试将元素从列表传递到for循环,当然我得到的经典错误'参数1必须是字符串而不是列表' - 对于os.chdir()函数.
这是我的代码,任何建议,我如何解决上述错误,仍然将我的列表的元素传递给脚本的其余部分,所以它循环通过每一个将非常感谢!!
path= ['C:\\DataDownload\Administrative', 'C:\\DataDownload\Cadastral', 'C:\\DataDownload\Development']
for x in path[:]:
os.chdir(path)
#Remove all previous files from the current folder
for file in os.listdir(path):
basename=os.path.basename(file)
if basename.endswith('.DXF'):
os.remove(file)
if basename.endswith('.dbf'):
os.remove(file)
if basename.endswith('.kmz'):
os.remove(file)
if basename.endswith('.prj'):
os.remove(file)
if basename.endswith('.sbn'):
os.remove(file)
if basename.endswith('.sbx'):
os.remove(file)
if basename.endswith('.shp'):
os.remove(file)
if basename.endswith('.shx'):
os.remove(file)
if basename.endswith('.zip'):
os.remove(file)
if basename.endswith('.xml'):
os.remove(file)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
998 次 |
| 最近记录: |