我对Python比较陌生,我的代码存在问题:
java.lang.NoSuchMethodError: org.apache.commons.validator.Validator.addResource(Ljava/lang/String;Ljava/lang/Object;)V
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:387)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at com.cibc.tbrm.isis.ceas.common.ui.servlet.AuthenticateServletFilter.doFilterInternal(AuthenticateServletFilter.java:94)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at com.cibc.tbrm.isis.ceas.common.ui.servlet.WebCommonServletFilter.doFilterInternal(WebCommonServletFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at com.cibc.tbrm.isis.ceas.common.ui.servlet.JamonServletFilter.doFilterInternal(JamonServletFilter.java:59)
at com.cibc.tbrm.isis.ceas.common.ui.servlet.SelectiveFilter.doFilter(SelectiveFilter.java:132)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at com.planetj.servlet.filter.compression.CompressingFilter.doFilter(CompressingFilter.java:270)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at com.cibc.tbrm.isis.ceas.common.ui.servlet.AccessServletFilter.doFilterInternal(AccessServletFilter.java:112)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at com.cibc.tbrm.isis.ceas.common.ui.servlet.ExceptionHandlingServletFilter.doFilterInternal(ExceptionHandlingServletFilter.java:57)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at com.cibc.tbrm.isis.ceas.common.ui.servlet.RreCommonServletFilter.doFilterInternal(RreCommonServletFilter.java:36)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3436)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)
Caused by: java.lang.NoSuchMethodError: org.apache.commons.validator.Validator.addResource(Ljava/lang/String;Ljava/lang/Object;)V
at org.apache.struts.validator.Resources.initValidator(Resources.java:316)
at org.apache.struts.validator.ValidatorForm.validate(ValidatorForm.java:146)
at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:942)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346)
my_dictionary键中的 days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
A = list(range(2))
B = list(range(2))
another_dict= {(a, b) : [[0, 1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7], [2, 3, 4, 5, 6, 7, 8]] for a in A for b in B}
my_dict = dict()
for a in A:
for b in B:
for c in range(len(another_dict[a, b])):
for day in range(len(another_dict[a, b][0])):
my_dict[(a, b, c, day)] = another_dict.get((a, b))[range(len(another_dict[a, b])).index(c)][range(len(another_dict[a, b][0])).index(day)]
可以采用0到6之间的值,我想用列表中day
(例如,我希望days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
代替(a, b, c, Monday)
)
是否可以将密钥(a,b,c,day)更改为d的新密钥(a,b,c,d)?
提前致谢!
答案 0 :(得分:1)
如果您想使代码保持不变,可以使用新密钥创建一个新字典:
new_dict = {}
for d in my_dict:
new_dict[(d[0],d[1],d[2],days[d[3]])] = my_dict[d]
否则,请更改以下行:
my_dict[(a, b, c, day)] = ...
为:
my_dict[(a, b, c, days[day])] = ...
输出:
{(0, 1, 1, 'Friday'): 5, (0, 1, 2, 'Thursday'): 5, (0, 0, 1, 'Saturday'): 6, (1, 0, 1, 'Saturday') ...
答案 1 :(得分:1)
您还可以使用enumerate
功能。改变这一行:
for day in range(len(another_dict[a, b][0])):
my_dict[(a, b, c, days[day])] = ...
为:
for day, d in enumerate(days):
my_dict1[(a, b, c, d)] =
由于days
列表与another_dict[a, b][0]
的大小相同,我可以自由地简化这一行。但我仍然觉得尼克的回答更优雅,更直接。