我有一个函数,它以一个以上的字典作为参数。我一直收到以下消息,语法有问题:
SyntaxError: non-keyword arg after keyword arg
基本上,我的代码将遍历文件名列表中的每个项,并获取要在compare()函数上传递的每个项的文件大小。我在传递多个词典时遇到问题。每个字典有两个键,它们是文件名和文件大小。我的代码如下:
def compare(previous,current):
tolerance = 0.4
if previous is None and current is None:
return " missing in both"
if previous is None:
return " new"
if current is None:
return " missing"
size_ratio = float(current)/previous
if size_ratio >= 1 + tolerance:
return " %d%% bigger" % round(((size_ratio - 1) * 100),0)
if size_ratio <= 1 - tolerance:
return " %d%% smaller" % round(((1 - size_ratio) * 100),0)
return " ok"
def compare_filesets(file_names, previous_data, current_data):
for item in file_names:
print (item + compare(previous_data.get('File Size'), current_data.get('File Size')) + "\n")
compare_filesets(file_names=['a.json', 'b.json', 'c.json'],
current_data= {"File Name": "a.json", "File Size": 1000}, {"File Name": "a.json", "File Size": 1000},
previous_data={"File Name": "a.json", "File Size": 1000}, {"File Name": "a.json", "File Size": 1000})