<div class="gmail_quote">On Fri, Oct 8, 2010 at 10:27 AM, Susana Iraiis Delgado Rodriguez <span dir="ltr"><<a href="mailto:susana.delgado_s@utzmg.edu.mx">susana.delgado_s@utzmg.edu.mx</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>Hi Alan:</div>
<div> </div>
<div>The ouput is coming from a cicle and some functions that I vae to do to execute an ogr2ogr command, in this output I ask the user for the name of a file and then make a module to get to the subprocess part:</div>
<div></div></blockquote><div><br></div><div><snip /></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div>##Eliminate duplicate lines from the txt into a new txt, status:100%<br>
a = open ("capas.txt","r")<br> catalogo = open ("unico.txt","w")<br> unique = set(a.read().split("\n"))<br>
catalogo.write("".join([line + "\n" for line in unique]))<br> catalogo.close()<br> a.close()<br></div></blockquote><div><br></div><div>I don't see how this is eliminating duplicate lines. To me it looks like it's just copying the contents of capas.txt into unico.txt and adding extra \n (line breaks), which might be what's breaking your next line.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div> <br>##Execute ogr2ogr command, status:75%<br> for line in open("unico.txt", "r"):<br>
p = subprocess.Popen(['C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr', line+'.shp', '-where', "\"LAYER='"+line+"'\"" , b+'.shp'])<br> </div>
<div>But when I executed it shows me an error in the layer's name:</div>
<div><br>>>> ERROR 1: Failed to identify field:LAYER=<br>ERROR 1: Failed to create file .shp file.<br>ERROR 4: Failed to open Shapefile `0<br>.shp'.</div>
<div> </div>
<div>I think the erros showed up because some of the layer's values are 0 and ' ', and obsviously you can't create a file from nothing on it. But I don`t know how to validate if a layer's value is equals to 0 or ' ', any idea what I'm doing wrong or how to fix it?</div>
</blockquote><div><br></div><div>Also, in your next e-mail, I noticed you're getting carriage returns (line breaks in your output). Since you're adding those line breaks above, you want to remove them before using them somewhere else. </div>
<div><br></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div class="gmail_quote"><div>p = subprocess.Popen(['C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr', line.replace("\n", "") +'.shp', '-where', "\"LAYER='"+ line.replace("\n", "") +"'\"" , b+'.shp'])</div>
</div></blockquote><div class="gmail_quote"><div><br></div><div>In the code above, I've changed the references to the variable <i>line</i> so that the \n's are replaced by 0-length strings. That should remove them from the Popen arguments.</div>
<div><br></div><div>Antonio Rodriguez</div></div>