os.path中的isfile正确用法

os.path.isfile()用于判断某一对象(需提供绝对路径)是否为文件

import os
dirct = '/home/workespace/notebook/'
for i in os.listdir(dirct):fulldirct = os.path.join(dirct, i)if os.path.isfile(fulldirct): #入参需要是绝对路径print(i)
data_url='http://biostat.mc.vanderbilt.edu/wiki/pub/Main/DataSets/titanic3.xls'
data_file_path=r'D:/_IDo/py_data/titanic3.xls'
#
if not os.path.isfile(data_file_path):result=urllib.request.urlretrieve(data_url,data_file_path)print('download:',result)
else:print(data_file_path,'data file already exists!')

参考文件链接


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部