LoadRunner为什么URL模式解决了Javas的所有问题(LoadRunner why is URL mode solving all my issues with Javas)
首先,我使用Wickets和JavaScripts对我的“Rich”Internett应用程序录制了一个脚本,并且它在重放时表现不佳。 但是,以URL模式录制解决了很多这些问题。 这是为什么? 一般来说,我假设以URL模式记录的脚本确实捕获了以下内容:
web_url("bootstrap-collapse-ver-12312478469.js" . . . "RecContentType=text/JavaScript",
并且这些调用即JavaScript操作网页使页面识别重放,因为Javascripts在重放期间实际执行。 在HTML模式下,这些Javascripts没有执行(在录制后没有在我的脚本中查看它们),因此页面没有适当的重播状态来识别它?
我的假设是否正确?
First I recorded a script against my "Rich" Internett Application having Wickets and JavaScripts and it did not go very well at replay. However, recording in URL mode solved a lot of these issues. Why is that? In general I assume that my script recorded in URL mode did capture things like:
web_url("bootstrap-collapse-ver-12312478469.js" . . . "RecContentType=text/JavaScript",
and these calls to i.e. JavaScript manipulating the web page made the page recognizabel the the replay because the Javascripts where actually executed during replay. In HTML mode these Javascripts where not executed (not seing them in my script after recording), and hence the page did not have the proper state for the replay to recognize it?
Is my assumption correct?
原文:https://stackoverflow.com/questions/15556074
最满意答案
(对不起,我真的认为这是对Alex Martelli回答的评论,因为我是基于他的;但是当我最初发布的时候,我没有足够的声望发表评论)
Alex的答案实际上并不能产生预期的结果。 我并不是指拥有一系列词组清单或列表之间缺少逗号(稍后会详述)。 但是最初的问题是, 通过竞争 ,所有国家和地区的奖牌汇总。 Alex的解决方案将回答:
> 'Germany': [{"Luge - Men's Singles": 'Gold'}, {"Luge - Men's Singles": 'Silver'}, {"Luge - Women's Singles": 'Gold'}, {"Luge - Women's Singles": 'Bronze'}, {'Luge - Doubles': 'Bronze'}]
但我相信最初的问题实际上是要求:
> 'Germany': [{"Luge - Men's Singles": ['Gold', 'Silver']}, {"Luge - Women's Singles": ['Gold', 'Bronze'}, {'Luge - Doubles': 'Bronze'}]
问题中的数据有点混乱,我看到两种可能性:
1)显示的数据实际上是三个不同的例子,任务是分别在每个列表中合并字典条目。 就是这样
[{'Germany': {"Luge - Men's Singles": 'Gold'}}, {'Germany': {"Luge - Men's Singles": 'Silver'}}, {'Italy': {"Luge - Men's Singles": 'Bronze'}}]
你要
['Germany': {"Luge - Men's Singles": ['Gold', 'Silver'], "Luge - Women's Singles": ['Gold', 'Bronze']}, 'Italy': {"Luge - Men's Singles": ['Bronze']}]
,给出
[{'Germany': {"Luge - Women's Singles": 'Gold'}}, {'Austria': {"Luge - Women's Singles": 'Silver'}}, {'Germany': {"Luge - Women's Singles": 'Bronze'}}]
你要
['Germany': {"Luge - Women's Singles": ['Gold', 'Bronze']}, 'Austria': {"Luge - Women's Singles": ['Silver']}]
等等。 我收集这是对问题最可能的解释。
以下代码可以做到这一点:
from collections import defaultdict merged = defaultdict(lambda: defaultdict(list)) for d in list_of_dicts: for k in d: for competition, medal in d[k].iteritems(): merged[k][competition].append(medal)
为上面显示的第一个列表运行此操作,即可获得
defaultdict(<function <lambda> at 0x1907db0>, {'Italy': defaultdict(<type 'list'>, {"Luge - Men's Singles": ['Bronze']}), 'Germany': defaultdict(<type 'list'>, {"Luge - Men's Singles": ['Gold', 'Silver']})})
2)第二种可能性是问题中的数据是一个单独的列表,其中包含3个列表,每个列表包含字典。 我认为这不是原始问题的意思,但是,因为我已经为此编写了代码,所以它是:)
from collections import defaultdict merged = defaultdict(lambda: defaultdict(list)) for L in listoflistsofdicts: for d in L: for k in d: for competition, medal in d[k].iteritems(): merged[k][competition].append(medal)
运行上面的代码来显示问题中显示的列表(添加了必要的逗号,您将得到:
defaultdict(<function <lambda> at 0x1904b70>, {'Italy': defaultdict(<type 'list'>, {"Luge - Men's Singles": ['Bronze']}), 'Austria': defaultdict(<type 'list'>, {'Luge - Doubles': ['Gold'], "Luge - Women's Singles": ['Silver']}), 'Latvia': defaultdict(<type 'list'>, {'Luge - Doubles': ['Silver']}), 'Germany': defaultdict(<type 'list'>, {'Luge - Doubles': ['Bronze'], "Luge - Men's Singles": ['Gold', 'Silver'], "Luge - Women's Singles": ['Gold', 'Bronze']}) })
请注意,这两个代码不会对奖牌类型进行排序(即,您最终可能会得到['Gold','Silver']或['Silver','Gold'])。
当然,如果在解决方案1)中使用了分隔列表,但需要将所有这些列表合并,只需将它们全部放在一个列表中,然后使用解决方案2)即可。
(Sorry, I really meant this as a comment on Alex Martelli's answer, since mine is based on his; but when I originally posted I didn't have enough reputation to comment)
Alex's answer doesn't actually generate the intended result. I don't mean the finer points of having a list of lists of dicts, or the lack of commas between the lists (more on that later). But the original question wanted, as a result, a compilation of all medals by country, by competition. Alex's solution will answer:
> 'Germany': [{"Luge - Men's Singles": 'Gold'}, {"Luge - Men's Singles": 'Silver'}, {"Luge - Women's Singles": 'Gold'}, {"Luge - Women's Singles": 'Bronze'}, {'Luge - Doubles': 'Bronze'}]
But I believe the original question actually asked for:
> 'Germany': [{"Luge - Men's Singles": ['Gold', 'Silver']}, {"Luge - Women's Singles": ['Gold', 'Bronze'}, {'Luge - Doubles': 'Bronze'}]
The data in the question is a bit confusing, I see two possibilities:
1) The data shown is actually three different examples, and the task is to merge dict entries within each list, separately. That is, given
[{'Germany': {"Luge - Men's Singles": 'Gold'}}, {'Germany': {"Luge - Men's Singles": 'Silver'}}, {'Italy': {"Luge - Men's Singles": 'Bronze'}}]
you want
['Germany': {"Luge - Men's Singles": ['Gold', 'Silver'], "Luge - Women's Singles": ['Gold', 'Bronze']}, 'Italy': {"Luge - Men's Singles": ['Bronze']}]
, given
[{'Germany': {"Luge - Women's Singles": 'Gold'}}, {'Austria': {"Luge - Women's Singles": 'Silver'}}, {'Germany': {"Luge - Women's Singles": 'Bronze'}}]
you want
['Germany': {"Luge - Women's Singles": ['Gold', 'Bronze']}, 'Austria': {"Luge - Women's Singles": ['Silver']}]
and so on. I gather this is the most likely interpretation of the question.
The following code does that:
from collections import defaultdict merged = defaultdict(lambda: defaultdict(list)) for d in list_of_dicts: for k in d: for competition, medal in d[k].iteritems(): merged[k][competition].append(medal)
Running this for the first of the lists shown above, you get
defaultdict(<function <lambda> at 0x1907db0>, {'Italy': defaultdict(<type 'list'>, {"Luge - Men's Singles": ['Bronze']}), 'Germany': defaultdict(<type 'list'>, {"Luge - Men's Singles": ['Gold', 'Silver']})})
2) The second possibility is that the data in the question is one single list, containing 3 lists, each of these containing dicts. I think this is not what the original question means, but, since I'd already written the code for that, here it is :)
from collections import defaultdict merged = defaultdict(lambda: defaultdict(list)) for L in listoflistsofdicts: for d in L: for k in d: for competition, medal in d[k].iteritems(): merged[k][competition].append(medal)
Running the code above for the lists shown on the question (with the necessary commas added, you get:
defaultdict(<function <lambda> at 0x1904b70>, {'Italy': defaultdict(<type 'list'>, {"Luge - Men's Singles": ['Bronze']}), 'Austria': defaultdict(<type 'list'>, {'Luge - Doubles': ['Gold'], "Luge - Women's Singles": ['Silver']}), 'Latvia': defaultdict(<type 'list'>, {'Luge - Doubles': ['Silver']}), 'Germany': defaultdict(<type 'list'>, {'Luge - Doubles': ['Bronze'], "Luge - Men's Singles": ['Gold', 'Silver'], "Luge - Women's Singles": ['Gold', 'Bronze']}) })
Please note that both of these codes don't sort medal types (i.e., you might end up with ['Gold', 'Silver'] or ['Silver', 'Gold']).
Of course, if you get separated lists as used in solution 1), but need a merge of all of them, simply bring them all together in a list, and use solution 2).
相关问答
更多-
[d for d in Account.accountList if d.customer.name == 'smith'] 你很亲密 问题出在这里 def __getitem__(self, i): return i 你可以看到下面发生了什么 MyClass["whatever"] == "whatever" #True "whatever"["asd"] #error 相反,我认为你可以使用 def __getitem__(self,item): return getattr(se ...
-
Python将字典的嵌套列表合并到单个字典列表中(Python merge nested list of dictionary to single list of dictionary)[2022-01-15]
data = list() for item in INPUTJSON: EXCEPTIONS = item["EXCEPTIONS"] del item["EXCEPTIONS"] for ex in EXCEPTIONS: tmp = dict() tmp.update(ex) tmp.update(item) data.append(tmp) print data data = list() for it ... -
(对不起,我真的认为这是对Alex Martelli回答的评论,因为我是基于他的;但是当我最初发布的时候,我没有足够的声望发表评论) Alex的答案实际上并不能产生预期的结果。 我并不是指拥有一系列词组清单或列表之间缺少逗号(稍后会详述)。 但是最初的问题是, 通过竞争 ,所有国家和地区的奖牌汇总。 Alex的解决方案将回答: > 'Germany': [{"Luge - Men's Singles": 'Gold'}, {"Luge - Men's Singles": 'Silv ...
-
在字典中查找具有相同值的嵌套列表[Python](Finding nested list with identical values in Dictionaries [Python])[2023-08-17]
你可以使用itertools.groupby : import itertools data = {'Invitees': [{'availableDates': ['2018-02-01', '2018-02-02'], 'lastName': 'Klein', 'highSchool': 'NorthwestHS', 'email': 'WKlein@***il.com', 'firstName': 'Will'}, {'availableDates': ['2018-02-04', '2018-01- ... -
如何过滤嵌套python字典和列表中的网页链接(How to filter web links in a nested python dictionaries and lists)[2019-12-29]
解 final=[x for x in my_search_field if 'questions' in x] 说明 1)在该行中使用x而不是my_search_field: final=[print(x) for x in my_search_field if 'questions' in my_search_field] 2)列表编辑无效。 尝试删除“打印”。 SOLUTION final=[x for x in my_search_field if 'questions' in x] EXPL ... -
如何使独特的python嵌套字典列表[关闭](How make unique a list of nested dictionaries in python [closed])[2023-09-08]
你需要跟踪你是否已经看过字典。 不幸的是,字典不可排除,也不会跟踪顺序,因此您需要将字典转换为可散列的字符。 键值对(作为元组)的frozenset()会做,但是你需要递归平坦化: def set_from_dict(d): return frozenset( (k, set_from_dict(v) if isinstance(v, dict) else v) for k, v in d.iteritems()) 这些frozenset()对象表示足以跟踪唯一项目 ... -
data = [ { "PricingOptions": { "Price": 51540.72, "Agents": [ 4056270 ] } }, { "PricingOptions": { "Price": 227243.14, "Agents": [ 4056270],} } ] newlist = sorted(data, key=lambda k: k['PricingOptions']["Price"]) print(newlist) 输出: [{'PricingOptions': {'P ...
-
获取嵌套字典中的列表(Get list in nested dictionaries)[2022-07-11]
尝试这个, dd = {} dd[1] = {'layer1' : 'A', 'FieldA':[[1,2,3], [99,22,13]], 'col': '#ff310021'} dd[2] = {'layer2' : 'B', 'FieldB':[[4,5,6], [10,33,22]], 'col': '#ff310011'} dd[3] = {'layer3' : 'C', 'FieldC':[[11,2,33], [2,5,1]], 'col': '#ff312221'} l = [] fo ... -
使用Python中的嵌套列表从字典列表中解析值(Parsing values from a list of dictionaries with nested list in Python)[2022-03-10]
最好的方法是展平复杂列表,你有这样的函数: def flatten(x): if isinstance(x, dict) : return [x] elif isinstance(x, collections.Iterable) : return [a for i in x for a in flatten(i)] else: return [x] 此函数将您的p_mat_list作为参数并返回单个字典列表。 get_list = f ... -
使用ast.literal_eval这是一种将Python文字(而不是eval ) eval为实际数据结构的安全方法。 那是: import ast with open('file.txt') as f: data = ast.literal_eval(f.read()) 如果你有超出支持的类型(字符串,字节,数字,元组,列表,dicts,集合,布尔值和None )的东西,你可以在这个答案中使用我的配方 。 Use ast.literal_eval which is a safe way of ...