Skip to main content

Dimensional Data Manipulation and Spreadsheet-like pretty grids.

Project description

PyGrids

Description

PyGrids is an module for storing and manipulating spreadsheet-like or grid-like information in python. It also uses numpy to speed up array operations.

Example

from grids import Grid

grid = Grid(5,3) # Create an empty 5x3 grid.

print(grid.get_cell(5,3)) # -> ∅ None
print(grid.get_cell(3,1)) # -> ∅ None

grid.update_cell(5,3,'Foo')
grid.update_cell(3,2,'Bar')

print()
print(grid.view())

Will output...

 


                             
            'Bar'             
                        'Foo' 

Installation

$ pip install pygrids

Grid Usage

Here's how you can use PyGrids.

Using cells

Getting cells

grid.get_cell(<x>, <y>)

Updating cells

grid.update_cell(<x>, <y>, <new_value>)

Overviewing cells

print(grid.view())

Iterating through cells

By Columns

for column in grid.y_by_x():
    for cell in column:
        print(x)

By Rows

for row in grid.x_by_y():
    for cell in row:
        print(y)

Saving Grids

You can save your grids by using their built-in save() method.

# Saves by default to grid1.dat or grid2.dat if that's taken or grid3.dat if grid2.dat it taken, etc.
grid.save()
# Or you can specify a specify a specific filename
grid.save(filename='mygrid.dat')

Loading Grids from file

You can also load your grids into python by using Grid's static load() method like so.

grid = Grid.load('mygrid.dat')

GridLog's

Each grid object tracks when it's methods are used and logs them to it's unique GridLog object. Let's take a look from out first example, what it's log would look like.

print(grid.log)

Looks something like

[GridLog created at [2020-10-21 20:30:11.230139]]:
-> [GET_CELL] (5, 3) at [2020-10-21 20:30:11.230171]
-> [GET_CELL] (3, 1) at [2020-10-21 20:30:11.230233]
-> [UPDATE_CELL] (5, 3, 'Foo') at [2020-10-21 20:30:11.230270]
-> [UPDATE_CELL] (3, 2, 'Bar') at [2020-10-21 20:30:11.230286]
-> [LOG_VIEW] () at [2020-10-21 20:30:11.230401]

MultiDimensionalArray's

Unlike grids, which are constrained to only 2 dimensions, MultiDimensionalArrays support arrays of any shape.

from grids import MultiDimensionalArray

myshape = [3,2,4,5]

array = MultiDimensionalArray(myshape)

Keep reading for how to use it

MultiDimensionalArray Usage

Here's a few example's on how use MultiDimensionalArray's

Updating and Getting Cells

target_coord = [1,2,3,4]

array.update_cell(target_coord, 'Foo')

print(array.get_cell(target_coord)) # Foo

License

This software is licensed by an MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyGrids-1.2.1.tar.gz (4.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page