我有一个成功处理单个文件的Python脚本.我正在尝试编写一个for循环,让它获取用户输入的目录中的所有文件.但是,它只处理目录中的一个文件.下面的代码后面是对"数据"进行分析的其余脚本.我是否需要以某种方式关闭for循环?这是我的第一个Python脚本.
import os
print "Enter the location of the files: "; directory = raw_input()
path = r"%s" % directory
for file in os.listdir(path):
current_file = os.path.join(path, file)
data = open(current_file, "rb")
# Here's an abridged version of the data analysis
for i in range(0, 10):
fluff = data.readline()
Input_Parameters = fluff.split("\t")
output.write("%f\t%f\t%f\t%f\t%.3f\t%.1f\t%.2f\t%.2f\t%s\n" % (Voc, Isc, Vmp, Imp, Pmax, 100 * Eff, IscErr, 100 * (1 - (P2 / Pmax)), file))
data.close()
Run Code Online (Sandbox Code Playgroud)