Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

tSystem component to execute python script

Hi all,
I have to execute python script by tSystem component.  Can Talend Studio store the script file .py or only the python code in Metadata or Documentation? I want that both job and script file are stored on Studio and not in a external folder. So, when I export the Job I will not worry about the script file .py
thanks all
Labels (4)
9 Replies
Anonymous
Not applicable
Author

Maybe you could store the code for the file inside the Job and then during the Job write the code out to a script file, which you then run using the tSystem component and then delete using the tFileDelete. This way you can parameterise the script file and do not need to worry about having files set up wherever you want to run the Job.
Anonymous
Not applicable
Author

How can I store the code in Studio? which components should I use?
thanks very much
Anonymous
Not applicable
Author

You can store the script in a context variable if you like. The String context variables should be able to hold your script. Alternatively you can a tJava component to store the script text in several globalMap key/value pairs.
You can use tSetGlobalVar component to interact with the globalMap variable, or interact with it using a tJava component. The code below is how you can store and retrieve String values....
To store....
globalMap.put("MyVarKey", "My text");
To retrieve....
((String)globalMap.get("MyVarKey"));
You can save ANY variable in the globalMap HashMap, hence you need to cast the value on the way out.
You can use the retrieval code in tMap components or tFile components for when you want to use it.
Anonymous
Not applicable
Author

hi all,
try & add py file with documentation (add documentation) in metatdata.
hope it helps
regards
laurent
Anonymous
Not applicable
Author

@rhall_2.0 - It's good strategy, but in this way I must to fix all " and ' characters in the python code.
@kzone - Hi,
 I have added the file py in Documentation, but how can I call it from tSystem?
Anonymous
Not applicable
Author

it had been stored in your repository (local ans svn repo) under documentation folder.
So you can call it from that repo
but it just a trick , not an optimize solution 0683p000009MACn.png
regards
Anonymous
Not applicable
Author

I'm not entirely sure you can refer to the Documentation objects at runtime. If you can great, I have learnt something :-)
If you can't and don't want to have to manipulate " and ' chars, you could read the file in as a byte array using a tFileInputRaw and output it as a byte array using a tFileOutputRaw component. This is a bit trickier and will require Java convert your types. It will also be meaningless to look at. But won't require any manual manipulation of " and ' chars. 
Anonymous
Not applicable
Author

unfortunatly it's just to keep python script beside other development.
but once compile , it will not be accessible as it. keep it in a cloud like drpbox and call it from that point.
Anonymous
Not applicable
Author

I was being very literal and looking to store the file inside the job. As kzone suggests, it is probably better to store it in a place you can get from anywhere like the cloud.
In my previous post I recommended reading the file in as a byte array and writing it out as a byte array. I should have explained that I meant at design time, read it in as byte array. Then store the byte array in a context variable. Then write it out from the context variable after having processed it back into a byte array. This will work as I have done something very similar with image files.
But kzone's suggestion is a lot easier and means you can edit your script file without touching the job.