# Pass input parameters to a script using pythonshell node

**URL:** <https://discourse.nodered.org/t/pass-input-parameters-to-a-script-using-pythonshell-node/56432>\
**Category:** General\
**Created:** [10 January 2022 23:10 UTC](https://discourse.nodered.org/t/pass-input-parameters-to-a-script-using-pythonshell-node/56432 "2022-01-10T23:10:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![miinch](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@miinch](https://discourse.nodered.org/u/miinch)\
**Post date:** [10 January 2022 23:10 UTC](https://discourse.nodered.org/t/pass-input-parameters-to-a-script-using-pythonshell-node/56432/1 "2022-01-10T23:10:57Z")

</div>

Hi all, I hope I can find some help regarding the following:

I'm using **pythonshell** node to execute a script for statistical prediction, using input parameters obtained from a weather station via MQTT (sun altitude and azimuth, direct and diffuse solar radiation).

My question: how to make the shell scrypt node to read input values from the server? Note: the script is not mine, so I'd prefer not to modify it, is it possible some way around?

Since the aim is predicting using the input data, I've tried to use the second approach in the link below, (passing the data as an argument), however I haven't found the way of doing it (I'm honestly new in Node-red and python).

> [@Passing parameter from node-red to python](https://discourse.nodered.org/t/passing-parameter-from-node-red-to-python/10340):
>
> Hello, I would like to pass parameter from Node-red to python script. 1.Is it possible to do that using: [https://flows.nodered.org/node/node-red-contrib-pythonshell](https://flows.nodered.org/node/node-red-contrib-pythonshell) Python script would be: a={Passed parameter} b=2 print(a\*b) Have also tried to understand: [Passing (msg.payload) in exec node to a python script function](https://discourse.nodered.org/t/passing-msg-payload-in-exec-node-to-a-python-script-function/3200) without success how to define script path in windows? In my case: C:\Users\admin\PycharmProjects\TEST\script.py

I've been experimenting, trying to output the parameters from the server @10sec to a txt file and then feed the python-shell-node (copied image of that part of the flow), but I just cannot find the way of doing this very simple example below:

```auto
> import sys
> print 'Hello ' + sys.argv[1]

```

 ![Q-input file](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0bed56adbcfa43abd0eb465a34da7b97d6531669.png)

I copy below part of the script that I believe, needs to be solved with the nodes:

```auto
class Emodel:
    def __init__ (
        self
    ):
	
	    self.model_pred = lgbm.Booster(model_file = config.MODEL_PRED)

   def return_predictions(
        self,
        altitude=None,
        ibn=None,
        idh=None,
        azimuth=None,
    ):
         #set vector values
        X[:,0] = altitude
        X[:,1] = ibn
        X[:,2] = idh
        X[:,3] = azimuth_sin
        X[:,4] = azimuth_cos

        pred = self.model_pred.predict(X)
 
        return pred

```

The output from **debug1** is the list of parameters:

> azimuth : msg.payload : Object  
> object  
> azimuth: 335.99097754452083  
> Idh: 71  
> altitude: 0  
> Ibn: 234  
> fully\_open: 0  
> blind\_angle: 10

Clearly I'm missing one important step, hope someone can give me a hint, thank you!

Miin

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [11 January 2022 08:48 UTC](https://discourse.nodered.org/t/pass-input-parameters-to-a-script-using-pythonshell-node/56432/2 "2022-01-11T08:48:19Z")

</div>

Does the python script work directly on the commandline ? If yes, maybe it is easier to execute it using an exec node.

---

<div class="post-metadata">

**Author:** ![miinch](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@miinch](https://discourse.nodered.org/u/miinch)\
**Post date:** [15 January 2022 20:45 UTC](https://discourse.nodered.org/t/pass-input-parameters-to-a-script-using-pythonshell-node/56432/3 "2022-01-15T20:45:54Z")

</div>

Hi, thank you for your reply, I' tried with the exec node and that brought some other issues, I've tried using pythonshell and **sys.argv[1]** to pass the arguments, but found some other problems that I'm addressing in a new post.  
[Pass input parameters to a phytonshell node using sys.argv: IndexError: list index out of range](https://discourse.nodered.org/t/pass-input-parameters-to-a-phytonshell-node-using-sys-argv-indexerror-list-index-out-of-range/56709)  
Thank you so much for your help.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 March 2022 20:46 UTC](https://discourse.nodered.org/t/pass-input-parameters-to-a-script-using-pythonshell-node/56432/4 "2022-03-16T20:46:33Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
