Literal strings can be typed in using either double quotes or single quotes. This can be handy when your string contains one quote or the other. You can also use the backslash character to escape special characters including these quotes. See the Strings page for more information.
Working with colors in Python is remarkably easy. You can simply use any tuple of 3 or 4 integers to represent a color in RGB or RGBA. For example, to set a label's text color to red, you can simple do something like this:
Additionally, the system.gui.color function allows you to pick a color in a similar fashion:
Python offers a variety of sequence types: most notably Lists and Tuples. These are ordered collections, meaning they are indexed and the sorted order is maintained. More information on these types can be found on the Lists and Tuples page.
A Dictionary is a very useful type that holds a set of key-value pairs. Unlike sequences, they are not ordered, so there is no need to sort them. Instead you give each Value in the dictionary a Key, which handles as a reference to Value. You may have used these in other languages and know them as hashmaps, maps, associative memories, or associative arrays. More information on Dictionaries can be found on the Dictionaries page.
For more information on JSON, see http://www.json.org.
A Dataset is a multidimensional collection of values, stored in a manner similar to how values on a spreadsheet appear. Python does not natively have a Dataset type. Instead these datasets were created for use inside of Ignition. There are two types of datasets:
- Dataset: Sometimes called a "Standard Dataset", this type is commonly used on many Vision Components, such as the Power Table or Chart, to display multiple values simultaneously.
- PyDataset: Short for "Python Dataset", these datasets act in a manner very similar to a Python Sequence when it comes to accessing specific values, or iteration (see Lists and Tuples). Ignition's built-in system functions that interact with the database typically return a PyDataset.
While there are two types of datasets, you can easily convert one type of dataset to the other. Additionally, you can easily create a dataset from a script.
Dates and times can be created in Python with the
time libraries. However, the Ignition's built-in system.date functions can also be used instead without having to import either library.
Using the In-Keyword
in keyword can be used to check the contents of something for a specific instance of another object. One use is to check the contents of a string for a certain substring:
in keyword can be used to look for a certain object inside of a sequence:
in keyword can be used in an expression on a
Python has many common operators as you would expect, or are at least familiar with if you've worked with other scripting languages.
These are just the basics. There are other operators, like bit shift operators and more. Read about them at: http://docs.python.org/library/stdtypes.html
In regards to Arithmetic Operators, the precision of the returned value depends on the data types of the arguments: including at least one float will return a float, otherwise, an integer is returned.
Addition. Note that the data type of the returned object depends on the data type of the arguments being used:
|Floored Division: will divide and return just the nearest integer value, even if dividing floats.|
Modulo: returns just the remainder of the dividend (the left argument) after being divided by the right argument.
In the example on the right, the 4.5 divides evenly twice, leaving 1.0 as a remainder.
|Power: raise the the number on the left to the power of the number on the right.|
|Returns True if either argument is True. If both are False, then returns False.|
|Returns True only if both arguments are True. Otherwise, returns False.|
|not||Returns a boolean value that represents that opposite value of the trailing expression: False becomes True, and True becomes False.|
|Less than or equal to|
|Greater than or equal to|
|Returns True if both arguments are referring to the same object, otherwise, returns False.|
|Returns True if both arguments are referring to different objects.|
Order of Operations
Note that there is an order of operations for Arithmetic and Boolean operators that can be modified with parenthesis. For arithmetic they are grouped in tiers and evaluated left-to-right within a given tier:
- Multiplication, Division, Modulo
- Addition, Subtraction
For Boolean operators: