# Online analysis with Python

**URL:** <https://mworks.discourse.group/t/online-analysis-with-python/192>\
**Category:** Support\
**Created:** [March 20, 2020, 11:18am UTC](https://mworks.discourse.group/t/online-analysis-with-python/192 "2020-03-20T11:18:40Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [March 24, 2020, 2:25pm UTC](https://mworks.discourse.group/t/online-analysis-with-python/192/4 "2020-03-24T14:25:59Z")

</div>

Hi Ant,

> I tried several combinations of python and mworks versions and could not manage to read datafiles neither online nor offilen.

Reading data files online (i.e. while they’re still being written) isn’t supported. However, you certainly should be able to read them offline. Can you tell me more about the errors you were encountering?

Regarding the “initialization of \_mworks raised unreported exception” error, is it possible that you’re seeing  
[this issue](https://stackoverflow.com/questions/38671630/initialization-of-multiarray-raised-unreported-exception-python)?

> I wanted to ask you in advance if you could give me a hint on how to set up the Python Bridge script and how to setup the mwel experiment itself to work with the bridge.

I’ve posted an updated [Python bridge plotting demo](https://github.com/dicarlolab-mworks/python_bridge_plotting_demo) on GitHub. It should be a good starting point for working with the Python bridge in the nightly build.

The `Conduit` class (in file [conduit.py](https://github.com/dicarlolab-mworks/python_bridge_plotting_demo/blob/master/conduit.py)) hides some of the hairier details and sets things up so that any matplotlib windows you open remain responsive. You should be able to use it with multiple experiments without modification.

The experiment-specific Python file ([python\_bridge\_plotting\_demo.py](https://github.com/dicarlolab-mworks/python_bridge_plotting_demo/blob/master/python_bridge_plotting_demo.py)) defines an event handler function that receives updated values for variables of interest, processes them in some way, and then draws one or more plots. It also invokes `Conduit.main`, passing it the custom function and the list of variable names to monitor. (Note that the function should not call `pyplot.show`, as that’s handled by `Conduit.main`.)

The only thing that the experiment file ([python\_bridge\_plotting\_demo.mwel](https://github.com/dicarlolab-mworks/python_bridge_plotting_demo/blob/master/python_bridge_plotting_demo.mwel)) needs to do is tell the Python script when to start/stop collecting events. This is done via two variables (called `start` and `stop` in the example). Assigning a value to the first variable tells the script to begin collecting events. Assigning a value to the second variable tells the script to stop collection events and invoke the event handler function on the collected events. The example assigns start/stop at the beginning/end of each trial, respectively.

To use the example, first load the experiment, then load the experiment-specific Python file via the Python script bridge window. The first time you load the script, you’ll also have to select the Python executable to use (e.g. `python3` in your local Anaconda installation).

> Also, is it the bridge going to be kept in future versions of MWorks?

Yes.

Cheers,  
Chris

---

_[View the full topic](https://mworks.discourse.group/t/online-analysis-with-python/192)._
