dataFileAttributes Property (Python)

The dataFileAttributes property of a Dataset object gets or sets datafile attributes for the dataset. The dataFileAttributes property behaves like a Python dictionary in terms of getting, setting, and deleting values. A Python dictionary consists of a set of keys, each of which has an associated value that can be accessed simply by specifying the key. In the case of datafile attributes, each key is the name of an attribute and the associated value is the value of the attribute, which can be a single value or a list or tuple of values. A list or tuple of values specifies an attribute array.

  • When setting attributes, attribute names and values must be given as quoted strings.

Retrieving Datafile Attributes. You retrieve datafile attributes for a dataset from the dataFileAttributes property of the associated Dataset object. You can retrieve the value of a particular attribute by specifying the attribute name, as in:

dsObj = spss.Dataset()
attr = dsObj.dataFileAttributes['attrName']

Attribute values are always returned as a tuple.

You can iterate through the set of datafile attributes using the data property, as in:

dsObj = spss.Dataset()
for attrName, attrValue in dsObj.dataFileAttributes.data.iteritems():
   print attrName, attrValue

Adding and Modifying Datafile Attributes. You can add new datafile attributes and modify existing ones. For example:

dsObj.dataFileAttributes['attrName'] = 'value'
  • If the attribute attrName exists, it is updated with the specified value. If the attribute attrName doesn't exist, it is added to any existing ones for the dataset.

Resetting Datafile Attributes. You can reset the datafile attributes associated with a dataset. For example:

dsObj.dataFileAttributes = {'attr1':'value','attr2':['val1','val2']}
  • You reset the datafile attributes by setting the dataFileAttributes property to a new Python dictionary. Any existing datafile attributes are cleared and replaced with the specified ones.

Deleting Datafile Attributes. You can delete a particular datafile attribute or all of them. For example:

#Delete a specified attribute
del dsObj.dataFileAttributes['attrName']
#Delete all attributes
del dsObj.dataFileAttributes