Python parameters

Discuss RoboTask here

Python parameters

Postby andydoc1 » Thu Aug 26, 2021 1:50 am

Sorry if I am being obtuse but this:
start_task(ext_name, params = '')
Method.
Start task by number or External Name.
Parameters
· ext_name - task number or external name
· params - parameters of the task to be launched. Empty string by default. Parameters can be set as text, one parameter per line :
parameter_name=parameter_value

is not at all clear

I have 3 parameters in the task 'ext_name' - how do i assign values from my script (where they are paramatised in a complex loop):
Code: Select all
from robotask import *
from datetime import datetime, timedelta

def save_and_run_config():
    rt.start_task('test parameters 3', params = 'p1={symbol},p2={todate},p3={fromdate}')

for symbol in symbols:
    for x in (w + timedelta(n) for n in range(numdays+1)):
        weekendadj = 0
        if((x.weekday()==0) or (x.weekday()==6)):
            continue
        elif(x.weekday()==1):
            weekendadj = 2
        todate = x.strftime("%Y.%m.%d")
        y = x - timedelta(days=(2+weekendadj))
        #check market days
        fromdate = y.strftime("%Y.%m.%d")
        save_and_run_config()

I have tried various different alternatives - no joy!!
andydoc1
 
Posts: 2
Joined: Tue Aug 24, 2021 5:37 pm

Re: Python parameters

Postby Oleg » Thu Aug 26, 2021 9:01 am

In order to run the task with parameters use the expression
Code: Select all
rt.start_task('TestParam', 'p1=Hello\np2=World\np3=Simple String')

This code starts the task with external name TestParam and pass 3 parameters: p1, p2, and p3
Look full examples below
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.

1-st task which receives parameters. The tasks has external name TestParam
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1163085779
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"TestParam"
Hide=INTEGER|0
ID=INTEGER|1773267551
LogOnAsUser=INTEGER|1
Name=STRING|"Show parameters"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER

[Actions\Action1]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""param1 = {p1}"""
Params=FOLDER

[Actions\Action1\Params]
icon=STRING|"1"
msg0=STRING|"param1 = {p1}"
msg1=STRING|"param2 = {p2}"
msg2=STRING|"param2 = {p3}"
msgcount=STRING|"3"
playsound=STRING|"0"
showmessage=STRING|"1"



2-nd task. It launches 1-st task with 3 parameters in python script
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1163085779
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task38"
Hide=INTEGER|0
ID=INTEGER|-1377614384
LogOnAsUser=INTEGER|1
Name=STRING|"Python Script (run task with parameters)"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER

[Actions\Action1]
ActionID=STRING|"A_SCRIPT_PYTHONSCRIPT"
Enabled=INTEGER|-1
Name=STRING|"Python Script"
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
script_0=STRING|"from robotask import *"
script_1=STRING|"rt = RoboTask()"
script_2=STRING|"rt.start_task('TestParam', 'p1=Hello\np2=World\np3=Simple String')"
script_count=STRING|"3"
script_type=STRING|"0"
search_paths_count=STRING|"0"
use_embedded=STRING|"1"

Oleg Yershov
Oleg
Site Admin
 
Posts: 2668
Joined: Thu Jan 01, 1970 1:00 am

Re: Python parameters

Postby Oleg » Thu Aug 26, 2021 9:44 am

In order to run the task with parameters use the expression
Code: Select all
rt.start_task('TestParam', 'p1=Hello\np2=World\np3=Simple String')


Another way to pass some parameters: use dictionary
Code: Select all
rt.start_task('TestParam', {"p1":"Hello","p2":"World","p3":"Simple String"})

It works too
Oleg Yershov
Oleg
Site Admin
 
Posts: 2668
Joined: Thu Jan 01, 1970 1:00 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron