Welcome to OStack Knowledge Sharing 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...