Note that there are some explanatory texts on larger screens.

plurals
  1. POargument of type 'NoneType' is not iterable
    primarykey
    data
    text
    <p>I am trying to open a directory that contains a series of XML's in one specific directory.<br> In the following code, I am iterating through each XML document, and I'm setting some "if statements" to read the text in the XML, find keywords and replace them and then write a new file to a new location.<br> I am getting the following error when I run the script:</p> <pre><code>Traceback info: File "Z:\ESRI\Python\Test Scripts\ElementTree6.py", line 62, in &lt;module&gt; if "%begdate%" in element.text: ... </code></pre> <p>Error Info:</p> <pre><code>argument of type 'NoneType' is not iterable </code></pre> <p>I have hard coded the directory to one specific XML and when I run through the if statements, they work fine.<br> It's when I try to set up to iterate through a series of XML's that I run into the error.<br> I searched through this site to see if I could final a solution, but all the issues are either different from mine or I am not quite understanding the work-around.</p> <p>I have used a number of print lines to test for outputs.<br> Everything works fine until I get to the if statement and then the error arises.</p> <pre><code># Location of XML's folderPath = r"Z:\data" # set variable to store files with extension ".xml" for filename in glob.glob(os.path.join(folderPath, "*.xml")): fullpath = os.path.join(folderPath, filename) # find files and split the filename from the directory path if os.path.isfile(fullpath): basename, filename2 = os.path.split(fullpath) #print "Basename = " + basename #print "Filename = " + filename2 # set variable to store XML structure from xml file root = ElementTree(file=r"Z:\data\\" + filename2) #Create an iterator iter = root.getiterator() #Iterate for element in iter: #print element.text if "%begdate%" in element.text: BEGDATE = element.text.replace("%begdate%", BEGDATEPARAM) element.text = BEGDATE </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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