I've defined a simple Python script to download a file:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> requests
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">import</SPAN> urllib
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">download_file</SPAN><SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
output_file_name <SPAN class="operator token">=</SPAN> get_output_file_name<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">with</SPAN> open<SPAN class="punctuation token">(</SPAN>output_file_name<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'wb'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> output_file<SPAN class="punctuation token">:</SPAN>
response <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">)</SPAN>
output_file<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> output_file_name<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">get_output_file_name</SPAN><SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
path <SPAN class="operator token">=</SPAN> urllib<SPAN class="punctuation token">.</SPAN>parse<SPAN class="punctuation token">.</SPAN>urlparse<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>path
base_file_name <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>basename<SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">)</SPAN>
scratch_folder <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scratchFolder
<SPAN class="keyword token">return</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>scratch_folder<SPAN class="punctuation token">,</SPAN> base_file_name<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> __name__ <SPAN class="operator token">==</SPAN> <SPAN class="string token">"__main__"</SPAN><SPAN class="punctuation token">:</SPAN>
url <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
download_file<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
and, I've created a script tool in a custom toolbox with an input parameter (the url of the file to download) and an output parameter (the path to the downloaded file).
To validate the tool, I need to set the value of the output parameter. I have a method for this in my script (get_output_file_name). How can I call this from within my Tool Validator code in the custom toolbox?