format Property (Python)

The format property of a Variable object gets or sets the display format of a variable.

Example

varObj = datasetObj.varlist['id']
#Get the variable format
format = varObj.format
#Set the variable format
varObj.format = (5,5,0)
  • When getting the format, the returned value is a string consisting of a character portion (in upper case) that specifies the format type, followed by a numeric component that indicates the defined width, followed by a component that specifies the number of decimal positions and is only included for numeric formats. For example, A4 is a string format with a maximum width of four, and F8.2 is a standard numeric format with a display format of eight digits, including two decimal positions and a decimal indicator.
  • When setting the format, you provide a tuple or list of three integers specifying the format type, width, and the number of decimal digits (for numeric formats) in that order. The width must include enough positions to accommodate any punctuation characters such as decimal points, commas, dollar signs, or date and time delimiters. If decimal digits do not apply, use 0 for the third element of the list or tuple. The available format types are listed in Variable Format Types (Python).

Notes

  • Allowable settings for decimal and width depend on the specified type. For a list of the minimum and maximum widths and maximum decimal places for commonly used format types, see Variable Types and Formats in the Universals section of the Command Syntax Reference, available in PDF from the Help menu and also integrated into the overall Help system.
  • Setting the width for a string variable will not change the defined length of the string. If the specified value does not match the defined length, it is forced to be the defined length.