Difference between revisions of "TruxtonOptions"

From truxwiki.com
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
 
=Methods=
 
=Methods=
  
==<code>exists(name: str) -> bool</code>==
+
==<code>exists(name: str) -> boolean</code>==
 
This will tell you if the named [[Configuration System|setting]] exists in the options.
 
This will tell you if the named [[Configuration System|setting]] exists in the options.
 
It will return [https://docs.python.org/3/library/constants.html#True True] if the option was specified somewhere, [https://docs.python.org/3/library/constants.html#False False] if the default value will be returned.
 
It will return [https://docs.python.org/3/library/constants.html#True True] if the option was specified somewhere, [https://docs.python.org/3/library/constants.html#False False] if the default value will be returned.
  
==<code>getbool(name: str) -> bool</code>==
+
==<code>getbool(name: str) -> boolean</code>==
 
This will retrieve a boolean [[Configuration System|setting]] from Truxton based on its name.
 
This will retrieve a boolean [[Configuration System|setting]] from Truxton based on its name.
 
If the <code>name</code> setting could not be found, [https://docs.python.org/3/library/constants.html#False False] will be returned.
 
If the <code>name</code> setting could not be found, [https://docs.python.org/3/library/constants.html#False False] will be returned.
Line 33: Line 33:
  
 
if __name__ == "__main__":
 
if __name__ == "__main__":
   main()
+
   sys.exit(main())
 
</source>
 
</source>

Latest revision as of 15:13, 27 January 2024

This class gives you access to configuration variables in Truxton.

Methods

exists(name: str) -> boolean

This will tell you if the named setting exists in the options. It will return True if the option was specified somewhere, False if the default value will be returned.

getbool(name: str) -> boolean

This will retrieve a boolean setting from Truxton based on its name. If the name setting could not be found, False will be returned.

getinteger(name: str) -> int

This will retrieve an integer setting from Truxton based on its name. If the name setting could not be found, zero will be returned.

getstring(name: str) -> str

This will retrieve a string setting from Truxton based on its name. If the name setting could not be found, an empty string will be returned.

Sample

import sys
sys.path.append('C:/Program Files/Truxton/SDK')
import truxton

def main():
  options = truxton.options()

  print( "CreateTheDatabase: " + str(options.getbool("CreateTheDatabase")))
  print( "dbport: " + str(options.getinteger("dbport")))
  print( "dbname: " + str(options.getstring("dbname")))

if __name__ == "__main__":
  sys.exit(main())