AJ R avatar AJ R committed 6b425b4

minor changes

Comments (0)

Files changed (4)

savReaderWriter/generic.py

                 # not self.encoding_and_locale_set --> nested context managers
                 raise SPSSIOError("Error setting IO interface", retcode)
         except TypeError:
-            raise Exception("Invalid interface encoding: %r (must be bool)")
+            msg = "Invalid interface encoding: %r (must be bool)" % ioUtf8
+            raise Exception(msg)
         if retcode < 0:
             checkErrsWarns("Problem setting ioUtf8", retcode)
 
         """Get/Set a whole record from/to a pre-allocated buffer"""
         args = c_int(self.fh), byref(self.caseBuffer)
         retcode = self.wholeCaseIn(*args)
-        if retcode != 0:
+        if retcode:
             checkErrsWarns("Problem reading row", retcode)
         record = list(self.unpack_from(self.caseBuffer))
         return record
             raise TypeError(msg)
         args = c_int(self.fh), c_char_p(self.caseBuffer.raw)
         retcode = self.wholeCaseOut(*args)
-        if retcode != 0:
+        if retcode:
             checkErrsWarns("Problem writing row\n" + record, retcode)
 
     def printPctProgress(self, nominator, denominator):

savReaderWriter/header.py

         --extended multiple dichotomy sets: {setName: {"setType": "E",
           "label": lbl, "varNames": [<list_of_varNames>], "countedValue":
            countedValue, 'firstVarIsLabel': <bool>}}
-	Note. You can get values of extended multiple dichotomy sets with 
+	    Note. You can get values of extended multiple dichotomy sets with
         getMultRespSetsDefEx, but you cannot write extended multiple dichotomy
         sets.
 
         varNameBuff = create_string_buffer(65)
         func = self.spssio.spssGetCaseWeightVar
         retcode = func(c_int(self.fh), byref(varNameBuff))
-        if retcode > 0:
+        if retcode:
             msg = "Problem getting case weight variable name"
-            raise SPSSIOError(msg, retcode)
+            checkErrsWarns(msg, retcode)
         return varNameBuff.value
 
     @caseWeightVar.setter
             args = c_int(self.fh), c_char_p(asciiGUID)
             func = self.spssio.spssSetDEWGUID
             retcode = func(*args)
-
-        if retcode:
+        else:
             msg = "Problem setting Data Entry info with function %r"
             checkErrsWarns(msg % func.__name__, retcode)

savReaderWriter/savReader.py

         I/O Module will be. Valid values are True (UTF-8 mode aka Unicode mode)
         and False (Codepage mode). Cf. SET UNICODE=ON/OFF (default = False)
     -ioLocale: indicates the locale of the I/O module. Cf. SET LOCALE (default
-        = None, which corresponds to locale.getlocale()[0])
+        = None, which corresponds to ".".join(locale.getlocale())
 
     Typical use:
-    savFileName = "d:/someFile.sav"
-    with SavReader(savFileName, returnHeader=True) as sav:
-        header = sav.next()
-        for line in sav:
+    savFileName = "someFile.sav"
+    with SavReader(savFileName, returnHeader=True) as reader:
+        header = next(reader)
+        for line in reader:
             process(line)
     """
 

savReaderWriter/savWriter.py

 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
-from savReaderWriter import *
 from header import *
 if cWriterowOK:
     cWriterow = cWriterow.cWriterow
       I/O Module will be. Valid values are True (UTF-8/unicode mode, cf. SET
       UNICODE=ON) or False (Codepage mode, SET UNICODE=OFF) (default: False)
     -ioLocale: indicates the locale of the I/O module, cf. SET LOCALE (default:
-      None, which is the same as locale.getlocale()[0])
+      None, which is the same as ".".join(locale.getlocale())
     -mode: indicates the mode in which <savFileName> should be opened. Possible
       values are "wb" (write), "ab" (append), "cp" (copy: initialize header
       using <refSavFileName> as a reference file, cf. APPLY DICTIONARY).
     varNames = ['var1', 'v2', 'v3']
     varTypes = {'var1': 5, 'v2': 0, 'v3': 0}
     savFileName = "test.sav"
-    with SavWriter(savFileName, varNames, varTypes) as sav:
-        sav.writerows(records)
+    with SavWriter(savFileName, varNames, varTypes) as writer:
+        for record in records:
+            writer.writerow(record)
     """
     def __init__(self, savFileName, varNames, varTypes, valueLabels=None,
                  varLabels=None, formats=None, missingValues=None,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.