Tool specification input and output files #2501
Replies: 2 comments 4 replies
-
The file names can be either hard coded or not. For example, you could have a script that requires (hard coded in the script) a file
The output files work similarly: you can hard code the entire file name or use wildcards for optional output files. When specifying the Input and Output files in the Specification editor, Toolbox will copy the files to the Tool's work directory so they are available for the script in a known location. Note, that you can specify subdirectories for the files as well. These will be relative to the work directory. These options expect some level of hard-coding: file names, or at least file extensions as well as relative locations to the work directory need to be known to the Tool script. There is another, more general way to provide input files to the script that does not require any kind of hard coding: command line arguments. You can set them up in Tool's properties tab. For example, in the project below, I have set up a Data connection that provides input files for the workflow. The files are visible in Available resources list in Tool's properties and I have dragged and dropped them into the Tool arguments list. Now my Python script can access the files by something like import sys
file_path1 = sys.argv[1]
file_path2 = sys.argv[2] Of course, more serious scripts would use the |
Beta Was this translation helpful? Give feedback.
-
Maybe we should add @soininen's answer as-is to the User Guide? |
Beta Was this translation helpful? Give feedback.
-
In https://spine-toolbox.readthedocs.io/en/latest/tool_specification_editor.html is the idea that when you define some input and output files, they can be referenced inside the program, script so that file names are not hard coded?
Beta Was this translation helpful? Give feedback.
All reactions