Python Variables in GRC: Difference between revisions
Mattcarrick (talk | contribs) |
Mattcarrick (talk | contribs) |
||
Line 8: | Line 8: | ||
GNU Radio Companion (GRC) uses Python data types to represent variables. The simplest data type are numbers. Numbers in Python can be floating point, | GNU Radio Companion (GRC) uses Python data types to represent variables. The simplest data type are numbers. Numbers in Python can be floating point, | ||
<pre>floatNumber = 3.14</pre> | <pre>floatNumber = 3.14</pre> | ||
or integers | or integers | ||
<pre>integerNumber = 2</pre> | <pre>integerNumber = 2</pre> | ||
Integers can be converted to floating point by casting using ''float()'', | Integers can be converted to floating point by casting using ''float()'', | ||
<pre>floatNumber = float(2)</pre> | <pre>floatNumber = float(2)</pre> | ||
and floating point numbers can be converted to integers using ''int()'', | and floating point numbers can be converted to integers using ''int()'', | ||
<pre>integerNumber = int(3.14)</pre> | <pre>integerNumber = int(3.14)</pre> | ||
Python uses both single quotes (') and double quotes (\'\'), to contain strings: | |||
<pre>singleQuoteString = 'string1'</pre> | |||
<pre>doubleQuoteString = "string2"</pre> | |||
* reference filter section that uses tuples to hold filter weights | * reference filter section that uses tuples to hold filter weights | ||
* lists | |||
* arrays | |||
== Using Python Types in GRC == | == Using Python Types in GRC == |
Revision as of 20:40, 20 January 2022
This tutorial describes how Python data types are used in GRC and how the variables are displayed.
The previous tutorial, Your First Flowgraph, shows how to build your first simple flowgraph. The next tutorial, Variables in Flowgraphs, describes how to use and modify variables in a more sophisticated flowgraph.
Introduction to Basic Python Data Types
GNU Radio Companion (GRC) uses Python data types to represent variables. The simplest data type are numbers. Numbers in Python can be floating point,
floatNumber = 3.14
or integers
integerNumber = 2
Integers can be converted to floating point by casting using float(),
floatNumber = float(2)
and floating point numbers can be converted to integers using int(),
integerNumber = int(3.14)
Python uses both single quotes (') and double quotes (\'\'), to contain strings:
singleQuoteString = 'string1'
doubleQuoteString = "string2"
- reference filter section that uses tuples to hold filter weights
- lists
- arrays
Using Python Types in GRC
- python data types accepted in variables
How GRC Displays Variable Values
- 32,000 -> 32k
- 0.25 -> 250m
The next tutorial, Variables in Flowgraphs, describes how to use and modify variables in a more sophisticated flowgraph.