Python Module: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
(Created page with "This block lets you embed a python module in your flowgraph. Code you put in this module is accessible in other blocks using the ID of this block. Example: If you put a...")
 
m (Add some notes for using the module.)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
This block lets you embed a python module in your flowgraph.
[[Category:Block Docs]]
 
<b>NOTE:</b> Do not use loop in your python module! It may cause GRC hang and you may have to kill the application.
 


Code you put in this module is accessible in other blocks using the ID of this
Code you put in this module is accessible in other blocks using the ID of this
Line 5: Line 8:


If you put
If you put
     a = 2
     a = 2
 
     def double(arg):
     def double(arg):
         return 2 * arg
         return 2 * arg
Line 17: Line 19:


to set parameters of other blocks in your flowgraph.
to set parameters of other blocks in your flowgraph.
Note that your custom imports will occur at the very beginning of the flowgraph's Python script, along with the other imports, so the module won't know about any parameters passed in (e.g. via command line args).

Latest revision as of 02:50, 10 August 2023


NOTE: Do not use loop in your python module! It may cause GRC hang and you may have to kill the application.


Code you put in this module is accessible in other blocks using the ID of this block. Example:

If you put

   a = 2

   def double(arg):
       return 2 * arg

in a Python Module Block with the ID 'stuff' you can use code like

   stuff.a  # evals to 2
   stuff.double(3)  # evals to 6

to set parameters of other blocks in your flowgraph.

Note that your custom imports will occur at the very beginning of the flowgraph's Python script, along with the other imports, so the module won't know about any parameters passed in (e.g. via command line args).