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.delgad...@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 + "'\"" 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=" Close Quote: " Add the content of the variable "line" from the unico.txt file: + line + Add another literal, composed of just the closing escaped quote to close the quote above (1) : "\"" See if this works, and let us know how it turns out. Antonio Rodriguez
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor