Previous topic

psychopy.tools.coordinatetools

Next topic

psychopy.tools.imagetools

This Page

Quick links

psychopy.tools.filetools

Functions and classes related to file and directory handling

psychopy.tools.filetools.toFile(filename, data)

Save data (of any sort) as a pickle file.

simple wrapper of the cPickle module in core python

psychopy.tools.filetools.fromFile(filename)

Load data from a pickle or JSON file.

psychopy.tools.filetools.mergeFolder(src, dst, pattern=None)

Merge a folder into another.

Existing files in dst folder with the same name will be overwritten. Non-existent files/folders will be created.

psychopy.tools.filetools.openOutputFile(fileName, append=False, delim=None, fileCollisionMethod='rename', encoding='utf-8')

Open an output file (or standard output) for writing.

Parameters:
fileName
: string
The desired output file name.
append
: bool, optional
If True, append data to an existing file; otherwise, overwrite it with new data. Defaults to True, i.e. appending.
delim
: string, optional
The delimiting character(s) between values. For a CSV file, this would be a comma. For a TSV file, it would be `` . Defaults to ``None.
fileCollisionMethod
: string, optional
How to handle filename collisions. This is ignored if append is set to True. Defaults to rename.
encoding
: string, optional
The encoding to use when writing the file. This parameter will be ignored if append is False and fileName ends with .psydat or .npy (i.e. if a binary file is to be written). Defaults to 'utf-8'.
Returns:
f
: file
A writable file handle.
Notes:

If no known filename extension is given, and the delimiter is a comma, the extension .csv will be chosen automatically. If the extension is unknown and the delimiter is a tab, the extension will be .tsv. .txt will be chosen otherwise.

psychopy.tools.filetools.genDelimiter(fileName)

Return a delimiter based on a filename.

Parameters:
fileName
: string
The output file name.
Returns:
delim
: string
A delimiter picked based on the supplied filename. This will be , if the filename extension is .csv, and a tabulator character otherwise.