[Tutor] PYTHON QUOTES ISSUE

taserian taserian at gmail.com
Thu Oct 7 19:15:03 CEST 2010


On Thu, Oct 7, 2010 at 12:48 PM, taserian <taserian at gmail.com> wrote:

> I'm adding some line breaks to make your text a little more readable.
>
> On Thu, Oct 7, 2010 at 9:55 AM, Susana Iraiis Delgado Rodriguez <
> susana.delgado_s at utzmg.edu.mx> wrote:
>
>  Hello members:
>>
>> How can I write a statement to execute the following:
>>
>
>
>> C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr R1G-GEODESIA.shp -where
>> "LAYER = 'R1G-GEODESIA'" tapalpa_05_plani_point.dbf
>>
>
>
>> I want my uotput to look like this.
>> Instead I'm getting this
>>
>
>
>> C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr T21-PUENTES.shp -where
>> LAYER=+line tapalpa_05_plani_line.shp
>>
>
>
>> In miy code line is a string given by the user:
>>
>> for line in open("unico.txt", "r").readlines():
>>      p = subprocess.Popen(['C:/Archivos de
>> programa/FWTools2.4.7/bin/ogr2ogr', line+'.shp', '-where', "LAYER='line'",
>> b+'.shp'])
>>
>> Any suggestions?
>>
>
> Without knowing specifics about what the subprocess.Popen function is
> expecting as parameters, I can only speculate, but it seems that the
> following *might* work (for extremely generous values of "*might*"):
>
> for line in open("unico.txt", "r").readlines():
>      p = subprocess.Popen(['C:/Archivos de
> programa/FWTools2.4.7/bin/ogr2ogr', line+'.shp', '-where', "\"LAYER='" +
> line + "'\"", b+'.shp'])
>
> Details about where the changes are:
> "\"LAYER='" + line + "'\""
>

Begin corrections (corrections start with a *)

Quote to begin the literal: "
> An escaped quote (1) so that there's a quote inside the literal: \"
> Some of the text that's meant to be unchanging: LAYER=
>
*Single Quote (2) to be included in the literal (which doesn't need to be
escaped): '

> Close Quote: "
>
Add the content of the variable "line" from the unico.txt file:  + line +
>
*Add another literal, composed of the single quote that closes (2) above,
then the closing escaped quote to close (1) : "'\""


>
> See if this works, and let us know how it turns out.
>
> Antonio Rodriguez
>

End of corrections.

Antonio Rodriguez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101007/f283f85f/attachment.html>


More information about the Tutor mailing list