如何使用 taglib(How to use taglib)
我有A班:
package a; public class A { private int x = 9; public int getX() { return x; } }
和ajsp.jsp文件:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <jsp:useBean id = "a" class = "a.A" /> <c:out value = "${a.x}" /> </body> </html>
当我运行它时,它会给出一个错误:
- org.apache.jasper.JasperException:/ajsp.jsp(11,0)PWC6236:根据标记文件中的TLD或属性指令,属性值不接受任何表达式
如果不是
<c:out value = "${ax}" />
我使用<jsp:getProperty property="x" name="a"/>
它会变得完美。 那么,问题是什么? 感谢提前。I have the class A:
package a; public class A { private int x = 9; public int getX() { return x; } }
and the ajsp.jsp file:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <jsp:useBean id = "a" class = "a.A" /> <c:out value = "${a.x}" /> </body> </html>
when i run it, it gives an error :
- org.apache.jasper.JasperException: /ajsp.jsp(11,0) PWC6236: According to TLD or attribute directive in tag file, attribute value does not accept any expressions
if instead of
<c:out value = "${a.x}" />
i use<jsp:getProperty property="x" name="a"/>
it goes perfect. So, what is the problem? Thank advance.
原文:https://stackoverflow.com/questions/3028922
最满意答案
您可以使用
functools.reduce
:from functools import reduce def some_func(df, cond_list): return df[reduce(lambda x,y: x&y, cond_list)]
或者,像@AryaMcCarthy所说,你可以使用运算符包中的and_ :
from functools import reduce from operator import and_ def some_func(df, cond_list): return df[reduce(and_, cond_list)]
或者与numpy一样 - 比如@ayhan说 - 这也是一个逻辑和减少:
from numpy import logical_and def some_func(df, cond_list): return df[logical_and.reduce(cond_list)]
所有三个版本都为您的样本输入生成以下输出:
>>> some_func(df, [cond1, cond2]) Sample DP GQ AB 1 HG_12_34_2 50 45 0.9 2 KD_89_9 76 67 0.7 >>> some_func(df, [cond1, cond2, cond3]) Empty DataFrame Columns: [Sample, DP, GQ, AB] Index: []
You can use
functools.reduce
for that:from functools import reduce def some_func(df, cond_list): return df[reduce(lambda x,y: x&y, cond_list)]
Or, like @AryaMcCarthy says, you can use
and_
from the operator package:from functools import reduce from operator import and_ def some_func(df, cond_list): return df[reduce(and_, cond_list)]
or with numpy - like @ayhan says - which has also a logical and reduction:
from numpy import logical_and def some_func(df, cond_list): return df[logical_and.reduce(cond_list)]
All three versions produce - for your sample input - the following output:
>>> some_func(df, [cond1, cond2]) Sample DP GQ AB 1 HG_12_34_2 50 45 0.9 2 KD_89_9 76 67 0.7 >>> some_func(df, [cond1, cond2, cond3]) Empty DataFrame Columns: [Sample, DP, GQ, AB] Index: []
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
使用任意数量的条件过滤Pandas Dataframe(Filter Pandas Dataframe using an arbitrary number of conditions)[2024-01-19]
pandas Series对象具有少于,大于等操作作为可以调用的方法。 所以df['field1'] < 3变成df['field1'].lt(3) 。 这不是非常重要,但它使代码更具可读性。 要实现您的要求,可以使用functools中的reduce函数and_运算符包中的and_ (等效于& )。 from functools import reduce from operator import and_ reduce(and_, (df.field1.lt(3), df.field2.lt(2), ... -
您可以使用functools.reduce : from functools import reduce def some_func(df, cond_list): return df[reduce(lambda x,y: x&y, cond_list)] 或者,像@AryaMcCarthy所说,你可以使用运算符包中的and_ : from functools import reduce from operator import and_ def some_func(df, cond_list) ...
-
在python pandas dataframe groupby上应用两个过滤条件(Apply two filter conditions on python pandas dataframe groupby)[2024-02-21]
在获取大小之前,使用isin并传递一个列表来过滤df: In [4]: len(df[df['A'].isin(['CA','CP'])]) Out[4]: 2 Use isin and pass a list to filter the df prior to getting the size: In [4]: len(df[df['A'].isin(['CA','CP'])]) Out[4]: 2 -
虽然可能有效的方法,但一种可能的方法是使用eval函数。 创建输入df : import pandas as pd import numpy as np data = pd.DataFrame() data['A']= [np.random.choice([1,2,3,4,5,6]) for i in range(10)] print(data) 输入df : A 0 4 1 3 2 3 3 1 4 1 5 2 6 3 7 6 8 2 9 1 现在,创建一个函数,使其iter ...
-
如果列是列表,是否可以过滤Pandas DataFrame列?(Is it possible to filter Pandas DataFrame column if column is a list?)[2023-11-01]
isin返回列值是否在您传递的内容中。 您想要检查您传递的内容是否在列值中。 据我所知,没有直接的快捷方式,但你可以使用map : >>> dafr[dafr.b.map(lambda x: 2 in x)] a b 0 1 [1, 2, 3] 1 2 [2, 3, 4] isin returns whether the column value is in what you pass. You want to check if what you pass is in t ... -
您可以使用groupby申请: In [11]: g = df1.groupby(level='Group') In [12]: g.apply(lambda x: x <= df2.loc[x.name]) Out[12]: 2000-01-04 2000-01-05 Group Element 1 A False False X False Fa ...
-
我相信你需要: #check B values maskB = read_data.filter(like='state') == 'B' print (maskB) state-01 state-02 state-03 0 True True True 1 True True False 2 True False False 3 False False False 4 False ...
-
PySpark DataFrame过滤器使用条件列表上的逻辑AND(PySpark DataFrame filter using logical AND over a list of conditions)[2023-08-25]
只需reduce谓词列表 from pyspark.sql.functions import lit from operator import and_ from functools import reduce df.where(reduce(and_, (col(c) != 0 for c in df.columns))) 要么 df.where(reduce(and_, (col(c) != 0 for c in df.columns), lit(True))) 如果您希望谓词列表可能为空。 例如 ...