Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

python - keyword can't be an expression error while using filter

I used below statements in Python but it is throwing an error

tbl_ProvJenny_AppGoalSetting = Table('tbl_ProvJenny_AppGoalSetting', metadata, autoload=True,autoload_with=engine,schema='dbo')
row= session.query(func.max(tbl_ProvJenny_AppGoalSetting.c.EffectiveDate)).filter(tbl_ProvJenny_AppGoalSetting.c.MerticTypeLkup=1002)
Error
    row= session.query(func.max(tbl_ProvJenny_AppGoalSetting.c.EffectiveDate)).filter([tbl_ProvJenny_AppGoalSetting].MerticTypeLkup=1002)
                                                                                     ^
SyntaxError: keyword can't be an expression

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This code:

filter([tbl_ProvJenny_AppGoalSetting].MerticTypeLkup=1002)

Is invalid syntax because a keyword argument can't look like [tbl_ProvJenny_AppGoalSetting].MerticTypeLkup - only names are allowed, like:

filter(some_name=6)

Did you mean to use a comma instead of the dot?

filter([tbl_ProvJenny_AppGoalSetting], MerticTypeLkup=1002)
   now you're passing two arguments  ^^^^

If you intended to set [tbl_ProvJenny_AppGoalSetting].MerticTypeLkup to 1002 and pass that to the function, do that:

[tbl_ProvJenny_AppGoalSetting].MerticTypeLkup = 1002
filter([tbl_ProvJenny_AppGoalSetting].MerticTypeLkup)

Actually, I think this error message is very misleading because "keyword" usually means "keyword of the language", like def, return and if, not "keyword argument", as in this case.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...