pyspssio.SPSSFile
- class pyspssio.SPSSFile(spss_file, mode='rb', unicode=True, locale=None)[source]
Bases:
objectBase class for opening and closing SPSS files
Methods
__init__(spss_file[, mode, unicode, locale])close()Close file
open()Open file
set_locale(locale)Set I/O module to a specific locale
Attributes
Number of cases
Compression level
File encoding reported by I/O module
I/O interface mode (Unicode or code page)
Check encoding compatibility
Basic file information
Number of variables
- property interface_encoding: int
I/O interface mode (Unicode or code page)
0 = SPSS_ENCODING_CODEPAGE
1 = SPSS_ENCODING_UTF8
- property file_encoding: str
File encoding reported by I/O module
- property is_compatible_encoding: bool
Check encoding compatibility
From I/O module documentation: “This function determines whether the file’s encoding is compatible with the current interface encoding. The result value … will be false when reading a code page file in UTF-8 mode, when reading a UTF-8 file in code page mode when reading a code page file encoded in other than the current locale’s code page, or when reading a file with numbers represented in reverse bit order. If the encoding is incompatible, data stored in the file by other applications, particularly Data Entry for Windows, may be unreliable.”
- open()[source]
Open file
Returns file handle that is used for most other I/O module functions.
- Return type:
int
Notes
Filenames are always encoded in UTF-8 regardless of interface mode and locale settings. This is to avoid issues where a filename uses special characters that aren’t available in the encoding defined by the file itself. For example, a Windows-1252 .sav file which uses Chinese (or other special multibyte characters) in its filename.
- property compression: int
Compression level
0 = No compression
1 = SAV
2 = ZSAV
- property release_info: dict
Basic file information
release number
release subnumber
fixpack number
machine code
floating-point representation code
compression scheme code
big/little-endian code
character representation code
- property var_count: int
Number of variables
- property case_count: int
Number of cases