p4lang / p4runtime-shell

An interactive Python shell for P4Runtime
Apache License 2.0
76 stars 40 forks source link

te.insert #131

Open skywood123 opened 3 weeks ago

skywood123 commented 3 weeks ago

Hi, I'm new to the tool. im trying to use as per the README.md I found that te.insert is not working. BMV2 table is not receiving the table entry. Whereas te.insert() is correctly calling out the function. Thank you.

antoninbas commented 3 weeks ago

If you are using the ipython-based shell, then we set the "autocall" property to ensure that functions can be called without parentheses: https://github.com/p4lang/p4runtime-shell/blob/8869f64f4e9215098919db129127791e249c4d3a/p4runtime_sh/shell.py#L3005

If you are using this project as a library in scripts (https://github.com/p4lang/p4runtime-shell?tab=readme-ov-file#using-p4runtime-shell-in-scripts), then there is no such thing as "autocall" and you need the parentheses.

Assuming you are using the ipython-based shell, then you may want to validate that autocall has been set properly:

c = get_config()
c.InteractiveShell.autocall
jafingerhut commented 3 weeks ago

If you are interested in examples of using p4runtime-shell from a Python program (not interactively), there are several examples in my p4-guide repository, including these: