For the model results in Model Builder, I am writing a python script tool which would write the results into a simple text (.txt) file. The problem I am encountering is that I do not know how to call the in-line model variable substitutions in a python script code. I have a few in-line model variables that I need to use for the results writing, for example, one comes from the Parse Path tool as a "Name_DBF". In code it is defined as route_name. How to complete the code correctly as I am getting syntax errors?
import arcpy
import os
import sys
workspace = r'C:\Users\Aura\Desktop\Andriui'
input_table = arcpy.GetParameterAsText(0)
route_name = %Name_DBF%
dvir_tipas = arcpy.GetParameterAsText(1)
# this is how you create a file in Python
file = open('C:\Users\Aura\Desktop\Andriui\RouteDesc.txt','w')
# create a row object to navigate your table
rows = ap.SearchCursor(input_table)
row = rows.next()
# for each row in your table, retrieve the value in the 'XXX' field, convert it
# to a string, write it to your output file, then move to the next line in both
# your input table and output file for row in rows:
file.write("Maršruto pavadinimas:" + str(route_name) + '\n')
file.write("Maršruto atstumas:" + " " + str(row.Atstumas_M) + " " + "km" + '\n')
file.write("Maršruto reljefo sąskaida:" + " " + str(row.Reljefo_S) + " " + "%" + '\n')
file.write("Maršruto sudėtingumas balais nuo 1 iki 3, kai 1 - lengvas, 3 - sunkus maršrutas" + " " + "-" + " " + str(row.Suapvalint) + '\n')
file.write("Apskaičiuota dviratininko tipui: " + " " + str(dvir_tipas) + " " )
del row, rows
file.close()
print "table field data successfully written into file"