Proper syntac to write string to config.py

456
2
Jump to solution
04-18-2013 12:18 PM
SuzanneRoulston-Doty
New Contributor II
Hello,

I am trying to write variable values to a config.py file so that I access the values from other scripts.  I am having problems properly saving an SQL query statement to the config.py file.

Sample of my code:

sqlSel = arcpy.GetParameterAsText(1) (e.g. sqlSel will have the value "CNTYNAME" = 'ALACHUA'

fo.write("sqlSel = \"" + sqlSel + '''\"''' + "\n") (I have tried variations of this syntax with no luck -
fo.write("sqlSel  = \"??? + sqlSel + "\???\n")

What is written to the config.py file;  [ATTACH=CONFIG]23615[/ATTACH]
sqlSel = ""CNTYNAME" = 'ALACHUA'" (CNTYNAME is not green indicating it is part of the string value)
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor
This is where the repr() function comes in very handy:

sqlSel = arcpy.GetParameterAsText(1) fo.write("sqlSel = {0}\n".format(repr(sqlSel)))

View solution in original post

0 Kudos
2 Replies
curtvprice
MVP Esteemed Contributor
This is where the repr() function comes in very handy:

sqlSel = arcpy.GetParameterAsText(1) fo.write("sqlSel = {0}\n".format(repr(sqlSel)))
0 Kudos
SuzanneRoulston-Doty
New Contributor II
Thank you - exactly what I needed!
0 Kudos