这是我的代码,现在有11个json文件作为输出,我需要将这些文件放在列表中,因为稍后需要解析它们:
import os
import shlex
import subprocess
#Set the environment variable
ECLIPSE_PATH ='C:/Users/AQ42770/Desktop/eclipse/plugins'
EQUINOX = ECLIPSE_PATH+'/org.eclipse.equinox.launcher_1.3.100.v20150511- 1540.jar'
MAIN='org.eclipse.core.launcher.Main'
ORGANIC='organic.Organic'
path='C:/Users/AQ42770/Documents/Android-ColorPicker'
for n in range(0,11):
path1= path+"/"+str(n)
outversion = "C:/Users/AQ42770/Documents/Android-ColorPicker/"+"out"+str(n)+".json"
commande='java -jar -Xms1g -Xmx20g "%s" %s -application %s -sf "%s" -src "%s"'
commande= commande % (EQUINOX, MAIN, ORGANIC, outversion, path1)
args = shlex.split(commande)
p = subprocess.Popen(args)
list=[]
list.append(outversion)
print(list)
它为我返回列表中的每个输出的问题我需要在同一列表中的所有输出文件才能读取多个json文件 这就是它的返回:
['C:/Users/AQ42770/Documents/Android-ColorPicker/out0.json']
['C:/Users/AQ42770/Documents/Android-ColorPicker/out1.json']
['C:/Users/AQ42770/Documents/Android-ColorPicker/out2.json']
['C:/Users/AQ42770/Documents/Android-ColorPicker/out3.json']
['C:/Users/AQ42770/Documents/Android-ColorPicker/out4.json']
['C:/Users/AQ42770/Documents/Android-ColorPicker/out5.json']
['C:/Users/AQ42770/Documents/Android-ColorPicker/out6.json']
['C:/Users/AQ42770/Documents/Android-ColorPicker/out7.json']
['C:/Users/AQ42770/Documents/Android-ColorPicker/out8.json']
['C:/Users/AQ42770/Documents/Android-ColorPicker/out9.json']
['C:/Users/AQ42770/Documents/Android-ColorPicker/out10.json']
PS:输出处于外向型,只需将11个输出添加到同一列表中
提前谢谢!
答案 0 :(得分:1)
您要按照其他人说的来修正代码,使其结构如下:
data=[]
for n in range(0,11):
...
data.append(outversion)
print(data)
正如其他人所说,请勿使用list
作为变量名。