OpenSesame
Rapunzel Code Editor
DataMatrix
Support forum
Python Tutorials
MindProbe
OpenSesame videos
Python videos
Supported by Supported by

Access items

instance items

The items object provides dict-like access to the items. It's mainly useful for programatically executing items.

An items object is created automatically when the experiment starts.

In addition to the functions listed below, the following semantics are supported:

Example:

# Programmatically prepare and run a sketchpad item.
items.execute(u'my_sketchpad')
# Check if an item exists
if u'my_sketchpad' in items:
        print(u'my_sketchpad exists')
# Delete an item
del items[u'my_sketchpad']
# Walk through all item names
for item_name in items:
        print(item_name)

function items._type(name)

Gets the type of an item.

Example:

print(items._type('target_sketchpad'))

Arguments:

  • name -- The name of an item.
    • Type: unicode

Returns:

The type of an item, or None if the item doesn't exist.

  • Type: unicode, NoneType

function items.execute(name)

Executes the run and prepare phases of an item, and updates the item stack.

Example:

items.execute(u'target_sketchpad')

Arguments:

  • name -- An item name.
    • Type: str

function items.new(_type, name=None, script=None, allow_rename=True)

Creates a new item.

Example:

items.new(u'sketchpad', name=u'my_sketchpad')
items[u'my_sketchpad'].prepare()
items[u'my_sketchpad'].run()

Arguments:

  • _type -- The item type.
    • Type: unicode

Keywords:

  • name -- The item name, or None to choose a unique name based on the item type.
    • Type: unicode, NoneType
    • Default: None
  • script -- A definition script, or None to start with a blank item.
    • Type: unicode, NoneType
    • Default: None
  • allow_rename -- Indicates whether OpenSesame can use a different name from the one that is provided as name to avoid duplicate names etc.
    • Type: bool
    • Default: True

Returns:

The newly generated item.

  • Type: item

function items.prepare(name)

Executes the prepare phase of an item, and updates the item stack.

Example:

items.prepare('target_sketchpad')
items.run('target_sketchpad')

Arguments:

  • name -- An item name.
    • Type: str

function items.run(name)

Executes the run phase of an item, and updates the item stack.

Example:

items.prepare('target_sketchpad')
items.run('target_sketchpad')

Arguments:

  • name -- An item name.
    • Type: str

function items.valid_name(item_type, suggestion=None)

Generates a unique name that is valid and resembles the desired name.

Example:

valid_name = items.valid_name(u'sketchpad', u'an invalid name')

Arguments:

  • item_type -- The type of the item to suggest a name for.
    • Type: unicode

Keywords:

  • suggestion -- The desired name, or None to choose a name based on the item's type.
    • Type: unicode, NoneType
    • Default: None

Returns:

A unique name.

  • Type: unicode
Supported by Supported by