Skip to content

API: Python already provides both 'flat' and 'vector' interfaces #21

@jonathanfine

Description

@jonathanfine

We can have Python provide both 'flat' and 'vector' interfaces, using a single code-base.

Let world denote the Minecraft world we are connected to. Python translates

world[1, 2, 3]

into

world.__getitem__((1, 2, 3))

Now write

vec = (1, 2, 3)

Python translates

world[pos]

to exactly the same as before, namely

world.__getitem__((1, 2, 3))

What's more, Python translates

world[pos1:pos2]

into

world.__getitem__(slice(pos1, pos2))

where the slice has start and stop attributes pos1 and pos2. From this we can have __getitem__ do what we think is the right thing.

We can even write, if there is need for it

world[pos1, pos2:pos3]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions