Python: SyntaxError: keyword can't be an expression

后端 未结 5 2265
清酒与你
清酒与你 2020-12-01 20:28

In a Python script I call a function from rpy2, but I get this error:

#using an R module 
res = DirichletReg.ddirichlet(np.asarray(my_values),al         


        
5条回答
  •  悲&欢浪女
    2020-12-01 20:58

    I just got that problem when converting from % formatting to .format().

    Previous code:

    "SET !TIMEOUT_STEP %{USER_TIMEOUT_STEP}d" % {'USER_TIMEOUT_STEP' = 3}
    

    Problematic syntax:

    "SET !TIMEOUT_STEP {USER_TIMEOUT_STEP}".format('USER_TIMEOUT_STEP' = 3)
    

    The problem is that format is a function that needs parameters. They cannot be strings. That is one of worst python error messages I've ever seen.

    Corrected code:

    "SET !TIMEOUT_STEP {USER_TIMEOUT_STEP}".format(USER_TIMEOUT_STEP = 3)
    

提交回复
热议问题