Sunday, 15 May 2011

python - Concatenating strings containing many quotations results in slashes in output -


I am trying to create a string for which to execute a SQL expression for specific double and single quotation letters needed.

I need to format my output like this:

  "full_striy" = 'allele rd' " 

In the following code sample, where the value of ALLENDALE RD will be a variable defined for a loop, I am trying to pass variable TOS in the query variable.

  tos = "ALLENDALE RD" query = '' "full_story" = '+ "' + + + + + '' + '' '' ''  
< P> And when I print the value of the query variable, I get this output:

  '' "full_stry" = \ 'ALLENDALE RD \' ''  < / Pre> 

Slash are caused by my query failure, I also tried to use a modulus operator to pass the value of the TOS variable, but get the same result:

  where = '"" full_striy Print "= \ '% s \' '' '(TOS) where' 'full_string' '= \' ALLENDALE RD \ ''  

How do I format my string in the correct format By adding a slash outside the expression?

What you see is your string

 > S = '"" full_Stree "= \' ALLENDALE RD \ '' '& gt; & Gt; & Gt; S # is printed without any print console repr '' "" full_stry "= \ 'ALLENDALE RD \' '> & gt; & gt; & gt; Print # string with" full_striy "=' Eldell R.D. '" 

Your real problem is that extra quotation at the beginning and end of your where-section.

this

  query = '' "Full_stri" = '+ "' + + '' + '' '' ' 

  query =' ' Full_Stree "= '+' + + + + + + '' ''  

It has been written more clearly

  Some other kind of recommendation  
  dataset = '/ path / "" = "" "" full_story "='% s'" "% tOS  

Two / featureclass / sizefile / or / table 'field = arcpy.AddFieldDelimiters (dataset,' full_stri ') whereclause = "% s ='% s'"% (field, TOS)

arcpy.AddFieldDelimiters ensures that the field name contains the appropriate quote style for the dataset you are using (use some double quotes and some use square brackets).


No comments:

Post a Comment