python读取脚本所在目录文件名,放到aa.txt文件中,然后读取aa.txt文件的每
python读取脚本所在目录文件名,放到aa.txt文件中,然后读取aa.txt文件的每一行,一行作为一个文件名,并打开,现在打开总是报错invalidargument:...
python读取脚本所在目录文件名,放到aa.txt文件中,然后读取aa.txt文件的每一行,一行作为一个文件名,并打开,现在打开总是报错invalid argument:'bb.txt\n'
代码如下
import os
path = os.getcwd()
for filename in os.listdir(path):
f = open('aa.txt','a')
f = write(filename)
f = write("\n")
f.close
f = open('aa.txt')
line = f.readline()
while line:
inFile = line
if inFile:
filehandle = open(inFile)
line = f.readline()
f.close()
filehandle.close() 展开
代码如下
import os
path = os.getcwd()
for filename in os.listdir(path):
f = open('aa.txt','a')
f = write(filename)
f = write("\n")
f.close
f = open('aa.txt')
line = f.readline()
while line:
inFile = line
if inFile:
filehandle = open(inFile)
line = f.readline()
f.close()
filehandle.close() 展开
1个回答
展开全部
import os
path = os.getcwd()
f = open('aa.txt','a')
for filename in os.listdir(path):
fullname=os.path.join(path,filename)
if os.path.isfile(fullname):
f.write(fullname)
f.write("\n")
f.close()
f = open('aa.txt')
for line in f:
infile=line.rstrip('\n')
filehandle=open(infile)
filehandle.close()
f.close()
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询