'How to fix "iterable expected, not int" when using csv.writerow?

I want to write to a CSV file the first index from the 1st and 2nd array.

Every time I've got

iterable expected, not int.

import csv
xd = [1,2,3,4,5]
dx = [5,4,3,2,1]
data = xd, dx
with open("houses.csv", "w", newline="") as p:
    cmon = csv.write(p, delimiter=",")
    for x in len(xd):
        yo = data[0][x], data[1][x]
        yo2 = list(yo)
        cmon.writerows(yo2)


Solution 1:[1]

As @Ghilas BELHADJ pointed out, you are iterating over an integer:

In this line:

for x in len(xd):

len(x) returns the length/count of x. To iterate over it call:

for x in range(len(x)):

This creates a list [0,..., len(x)-1] and then you iterate over it to get the indexes.

Solution 2:[2]

Your XSD file contains an element reference which refers to the XSD schema. That's unusual, but not wrong. The element content seems to be a snippet of XML schema. I suspect that you need to add an <xs:import> to your XSD file so that it can locate the XSD that describes XSDs.

You could do that as follows:

  • download the 'schema for schema' from the W3C web site
  • add a schemaLocation attribute to your XSD as a hint to your XML processor

However, you should be able to add an 'entity resolver' in your Spring environment which will allow the Spring XML processor to locate the XSD via its URL.

Before you ask...I don't know why .Net did not report this error, but it's possible that .Net auto-resolves the schema-for-schema.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 epsilonmajorquezero
Solution 2 kimbert