Note that there are some explanatory texts on larger screens.

plurals
  1. POBuild CSV from parse files python
    text
    copied!<p>I am building a small database (for personal use), from over a 1000 files. I am looking for specific word, but the issue that I have if the word is not contained in the file how can i write a NoData line, what I would like to have is:</p> <ul> <li>Africa Botswana test 51.1922546 -113.9366341 </li> <li>Africa Kenya Skydive Kenya -13.788388 33.78498</li> <li>Africa Malawi Skydive Malawi NoData NoData</li> <li>Africa Mauritius SkyDive Austral 30.5000854 -8.824510574</li> <li>Africa Morocco Beni Mellal NoData NoData</li> </ul> <blockquote> <pre><code>for i in os.listdir(Main_Path): if "-" in i: for filename in os.listdir(Main_Path+i): if ".dat" in filename and os.path.isdir(Main_Path+i): f_split = filename.split("-") if len(f_split) == 4: continent.append(f_split[0]) country.append(f_split[1]) state.append(f_split[2].split(".")[0]) else: continent.append(f_split[0]) country.append("") state.append(f_split[1].split(".")[0]) d = open(Main_Path+i+"/" + filename, "r") files = d.readlines() d.close() for k, line in enumerate(files): if "Dropzone.com :" in line: dzname.append(line.split(":")[1].strip()) elif 'id="lat"' in line: lat.append(line.split("=")[3].split('"')[1].strip()) myFile = open(Main_Path+"MYFILE.csv", "wb") wtr= csv.writer( myFile ) for a,b,c,d,e in zip(continent,country,state,dzname,lat): wtr.writerow([a,b,c,d,e]) myFile.close() </code></pre> </blockquote> <p>I am stack "elif 'id="lat"' in line:" because it adds to the list "lat" only the files which contains id = lat. I do understand why but I would like the parser to return and add to the list an NoData</p> <p>sorry i wrote the question from another comp.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload