Storing state with Python

Copper Contributor

Hi,

 

I am having trouble working out how I would do something like this:

 

It appears that the state of the python context is completely wiped between recalculations. I am trying to find a way (ANY way) of storing some state across recalculations which can affect that state itself. As a simple proof of concept, Conway's Game of Life. This requires updating a range of cells based upon that range itself which seemingly cannot happen despite there being no actual technical limitation to stop it other than a needlessly imposed inability to modify existing data which makes no sense. I simply cannot find any way to store the state of the grid across iterations without a circular reference. Variables are wiped upon recalculation so i'm a bit lost.

 

As it stands I cannot find a way to do this. the xl function appears to take a hardcoded value for cell range, so I cannot fetch cell data dynamically, and any kind of circular reference just doesn't work.

 

All in all I was looking forward to python being added to excel but it's so limited with this problem that I really hope there is SOME kind of workaround. The concept of having an excel spreadsheet with python code is very appealing but with this limitation it's really not much better than using existing formulas...

2 Replies

It may help to send the Excel team feedback through File | Feedback. Python functionality started rolling out to insiders a week ago so MS could use the feedback. I'm an insider and don't yet have access to Python within Excel.

Ah, hope you get access to it sooner rather than later. Hopefully someone is able to post a workaround for this since right now this addition will only allow "linear" programming, e.g take some data, do some process, and dump it somewhere else. If it would be allowed to work more freely and transfer data back and forth across ranges it would open up such an incredible amount of power.