spss.Cursor Class (Python)
spss.Cursor(var, accessType, cvtDates, isBinary). Provides the ability to read cases, append cases, and add new variables to the active dataset.
- The optional argument var specifies a tuple or a list of variable index values representing position in the active dataset, starting with 0 for the first variable in file order. This argument is used in read or write mode to specify a subset of variables to return when reading case data from the active dataset. If the argument is omitted, all variables are returned. The argument has no effect if used in append mode.
- The optional argument accessType specifies one of three usage modes: read ('r'), write ('w'), and append ('a'). The default is read mode.
- The optional argument cvtDates specifies a set of IBM® SPSS® Statistics variables
with date or datetime formats to convert to Python
datetime.datetime
objects when reading data from IBM SPSS Statistics. The argument is a sequence of variable index values representing position in the active dataset, starting with 0 for the first variable in file order. If the optional argument var is specified, then cvtDates must be a subset of the index values specified for var. You can specify to convert all date or datetime format variables withcvtDates='ALL'
, or by setting cvtDates to a list or tuple with the single element'ALL'
, as incvtDates=['ALL']
. When'ALL'
is specified in conjunction with var, it refers to all variables specified in var. If cvtDates is omitted, then no conversions are performed. Variables included in cvtDates that do not have a date or datetime format are ignored in terms of the conversion. cvtDates applies to read and write mode and cannot be used in append mode.Note: Values of variables with date or datetime formats that are not converted with cvtDates are returned as integers representing the number of seconds from October 14, 1582.
- The optional Boolean argument isBinary (introduced in version
22) specifies the method that is used by the
Cursor
class to work with the data in the active dataset. It has no effect onCursor
functionality. By default isBinary is set toTrue
, which typically provides the best performance but might require more temporary disk space. When isBinary is set toFalse
, theCursor
class uses the same method for working with the data as in versions before version 22. - You cannot use the
spss.Submit
function while a data cursor is open. You must close or delete the cursor first. - Only one data cursor can be open at any point in the program block.
To define a new data cursor, you must first close or delete the previous
one. If you need to concurrently work with the data from multiple
datasets, consider using the
Dataset
class. - Instances of the
Cursor
class are implicitly deleted at the end of aBEGIN PROGRAM-END PROGRAM
block, and therefore they do not persist acrossBEGIN PROGRAM-END PROGRAM
blocks. - The
Cursor
class honors case filters specified with theFILTER
orUSE
commands.