OpenSesame videos
Python videos
Supported by Supported by

Access the file pool

instance pool

The pool object provides dict-like access to the file pool. When checking whether a file is in the file pool, several folders are searched. For more details, see [folders].

A pool object is created automatically when the experiment starts.

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

Example 1:

# Get the full path to a file in the file pool
print(u'The full path to img.png is %s' %  pool[u'img.png'])
# Check if a file is in the file pool
if u'img.png' in pool:
        print(u'img.png is in the file pool')
# Delete a file from the file pool
del pool[u'img.png']
# Walk through all files in the file pool. This retrieves the full
# paths.
for path in pool:
        print(path)
# Check the number of files in the file pool
print(u'There are %d files in the file pool' % len(pool))

Example 2:

# Get the full path to an image from the file pool and show it
if u'img.png' in pool:
        print(u'img.png could not be found!')
else:
        image_path = pool[u'img.png']
        my_canvas = Canvas()
        my_canvas.image(image_path)
        my_canvas.show()

function pool.add(path, new_name=None)

Copies a file to the file pool.

Example:

pool.add(u'/home/username/Pictures/my_ing.png')

Arguments:

  • path -- The full path to the file on disk.
    • Type: str, unicode

Keywords:

  • new_name -- A new name for the file in the pool, or None to use the file's original name.
    • Type: str, NoneType
    • Default: None

function pool.fallback_folder()

No description specified.

Example:

if pool.fallback_folder() is not None:
        print(u'There is a fallback pool folder!')

Returns:

The full path to the fallback pool folder, which is the __pool__ subfolder of the current experiment folder, or None if this folder does not exist. The fallback pool folder is mostly useful in combination with a versioning system, such as git, because it allows you to save the experiment as a plain-text file, even when having files in the file pool.

  • Type: unicode, NoneType

function pool.files()

Returns all files in the file pool.

Example:

for path in pool.files():
        print(path)
# Equivalent to:
for path in pool:
        print(path)

Returns:

A list of full paths.

  • Type: list

function pool.folder()

Gives the full path to the (main) pool folder. This is typically a temporary folder that is deleted when the experiment is finished.

Example:

print(u'The pool folder is here: ' % pool.folder())

Returns:

The full path to the main pool folder.

  • Type: unicode

function pool.folders(include_fallback_folder=True, include_experiment_path=False)

Gives a list of all folders that are searched when retrieving the full path to a file. These are (in order):

  1. The file pool folder itself, as returned by [folder].
  2. The folder of the current experiment (if it exists)
  3. The fallback pool folder, as returned by [fallback_folder] (if it exists)

Example:

print(u'The following folders are searched for files:')
for folder in pool.folders():
        print(folder)

Keywords:

  • include_fallback_folder -- Indicates whether the fallback pool folder should be included if it exists.
    • Type: bool
    • Default: True
  • include_experiment_path -- Indicates whether the experiment folder should be included if it exists.
    • Type: bool
    • Default: False

Returns:

A list of all folders.

  • Type: list

function pool.in_folder(path)

Checks whether path is in the pool folder. This is different from the path in pool syntax in that it only checks the main pool folder, and not the fallback pool folder and experiment folder.

Example:

print(pool.in_folder('cue.png'))

Arguments:

  • path -- A file basename to check.
    • Type: str

Returns:

No description

  • Type: bool

function pool.rename(old_path, new_path)

Renames a file in the pool folder.

Example:

pool.rename(u'my_old_img.png', u'my_new_img.png')

Arguments:

  • old_path -- The old file name.
    • Type: str, unicode
  • new_path -- The new file name.
    • Type: str, unicode

function pool.size()

No description specified.

Example:

print(u'The size of the file pool is %d bytes' % pool.size())

Returns:

The combined size in bytes of all files in the file pool.

  • Type: int
Supported by Supported by