pyspread FAQ

Q: What kind of expressions can cell contain?
A: A cell cannot contain statements such as

for i in xrange(10): pass

However, it can contain a list comprehension or a generator expression.
If you want to program more complex algorithms, use the Macro Editor.
There, you can define one (!) function at a time that uses arbitrary Python
code and is callable from any cell.

Example:
Type in the macro editor:

def factorize(number):
    """Silly factorizing algorithm for demonstration purposes only"""
    counter = 1
    result = []
    while counter <= number:
        if number % counter == 0:
            result.append(counter)
        counter += 1
    return result

And in the cell:

 factorize(25)

Result is:

 [1 5 25]


Q: Is using the variable S the only way for reading values of a cell(s)?
A: The variable S is the very grid object. It can be used in various ways,
such as using its attributes and methods. One example is the spread method.

The object S has the attributes sgrid (string grid), fgrid (function grid),
macros (Macro dict) and resultcache and unredo (do not use these). There are
some method to access and manipulate the data. Since the attributes fgrid
and sgrid are numpy object grids, all numpy methods can be used directly.
When accessing (and slicing) S, you actually call a method that evaluates
S.fgrid. When you set an item in S, the sgrid item is set but it is not
automatically evaluated or updated. Have fun poking around in the S object.

Q: Is S.spread the only way to write to a cell using its absolute/relative
address?
A: Nope. However, it is the preferred way.
Try this out:

S[1,0,0] = '2'

Only after selecting the cell (1,0,0), the string 2 will appear and it will
be updated.
Note the error message in the original cell.

Q: How to write to cells from macro?
A: S.spread is your friend
Macro:

def test(a):
    S.spread(a, (1, 0, 0))
 

Grid:

test(3)


Q: What are boundaries for the number of rows/columns/sheets?
A: Ultimately these are limited by your memory (and maybe your stack
restriction if any). Pyspread warns you about memory consumption if the grid
size is too large for a normal 2GB system. If you proceed you should be able
to create really large grids (especially on 64 bit machines with much RAM).
The maximum number of rows that I have tried out is 10 000 000.

However, pyspread does not use sparse grids due to performance issues.
If you really need larger grids, please contact me.

Q: I'd like to exact data from a saved .pys file it without using the GUI,
e.g. I'd like to open one in a script and read things from it.
A: The .pys format is a bzip2-ed pickle dump of the numpy object array that
contains the strings that are entered in the cells.
Example:

>>> import bz2 
>>> infile=bz2.BZ2File('test.pys','r') 
>>> import cPickle as pickle 
>>> import numpy 
>>> data = pickle.load(infile) 
>>> data 
array([[[rpy = __import__("rpy"), 1, ], 
[, 3, ], 
[, -4, ], 
...,  
[, , ], 
[, , ], 
[, , ]], 
 
[[__import__("math"), 2, ], 
[, 4, ], 
[, 5, ], 
...,  
[, , ], 
[, , ], 
[, , ]], 
 
[[a = numpy.arange(-1,1,.001), 3, ], 
[, 35, ], 
[, 2, ], 
...,  
[, , ], 
[, , ], 
[, , ]], 
 
...,  
[[, , ], 
[, , ], 
[, , ], 
...,  
[, , ], 
[, , ], 
[, , ]], 
 
[[, , ], 
[, , ], 
[, , ], 
...,  
[, , ], 
[, , ], 
[, , ]], 
 
[[, , ], 
[, , ], 
[, , ], 
...,  
[, , ], 
[, , ], 
[, , ]]], dtype=object) 
>>> infile.close()