Beginners Interactive NetLogo Dictionary (BIND)
Farsi / Persian
NetLogo Models Library:
Note: If you download the NetLogo application, every model in the Models Library is included.
This model shows how to use NetLogo's
py extension to interact with Python. This extension allows users with Python installed on their computer to write Python code in their NetLogo model and to share data back and forth between the Python and NetLogo.
First, the model sets up Python with the
py:python primitives. The default
python found on the system will be used. This step is required for models using the Python extension. If you do not have Python installed on your computer, you will need to install it on your computer outside of NetLogo. Once the Python environment is setup, it's available until the model is closed.
This model uses a few basic Python packages,
os, to get information and do calculations that would be difficult or impossible in NetLogo. The packages are made available by using
py:run to execute the Python
import commands. The key to interacting with the packages is using
py:set to set a variable value and pass data into the Python extension and
py:runresult to get data back out of Python to use in NetLogo.
Check out the Python
math package documentation and see if there are any other calculations it can do that NetLogo doesn't natively support and try to make them work.
While the uses demonstrated are convenient when needed, the real power of Python is in its scientific packages, like
scikit-learn and more.
There is a bundle of other Python extension demo models,
py-demo-models.zip, available on the Python extension site.