Hi all,

I found “ERROR: Invalid python command” occurred when I have more than 2 input in python function:

variable myN equal 5

variable myM equal 6

======= **This works**===================================

python factorial input 1 v_myN return v_fac format ii here “”"

def factorial(n):

if n == 1: return n

return n * factorial(n-1)

“”"

======= **This doesn’t work**===============================

python factorial input 2 v_myN v_myM return v_fac format ii here “”"

def factorial(n,m):

if n == 1: return n*m

return n * factorial(n-1)

“""

Any help would be appreciated.

Regards,

Wenting

Hi all,

I found “ERROR: Invalid python command” occurred when I have more than 2 input in python function:

variable myN equal 5

variable myM equal 6

======= **This works**===================================

python factorial input 1 v_myN return v_fac format ii here “”"

def factorial(n):

if n == 1: return n

return n * factorial(n-1)

“”"

======= **This doesn’t work**===============================

python factorial input 2 v_myN v_myM return v_fac format ii here “”"

def factorial(n,m):

if n == 1: return n*m

return n * factorial(n-1)

“""

it cannot work. you define factorial() to have two arguments (and no defaults), and then you call it (recursively) with only one argument. that is an error and LAMMPS tells you just that.

axel.

Hi Axel,

Thanks for your reply. The previous example has a programming error. Please see the following code:

ERROR: Invalid python command (…/python_impl.cpp:186)

Last command: python my_multiply input 2 5 6 return v_fac format ii here “”"

def my_multiply(n,m):

return n*m

“”"

I still got the error.

Regards,

Wenting

this is a *different* error. you specify to have two arguments and one return value, but in the format keyword you only flag two integers (instead of three). so LAMMPS is correct, your python command is invalid.

axel.

Hi Axel,

Thanks again. I am relying to the mailling list now. I am supposed to use ‘format iii’ since I have 2 input and 1 return value.

Regards,

Wenting