Question: I need to count how many lines in the returned value in variable"data",but it doesn't accept the variable as how it is, here is what i did and the error:

```
sum_lines =0
data=subprocess.call(["nova list"],shell=True)
for line in data:
        print line
       sum_lines += 1
print sum_lines

```

The error 

```
  File "./code.py", line 9, in <module>
    for line in data:
TypeError: 'int' object is not iterable

```

THE SOLUTION: i had to use check\_output 

```
data=subprocess.check_output("nova show "+new+"."+projid_new, shell=True)
for line in data.splitlines():
        sum_lines +=1

```

Answer: 
According to docs, [`subprocess.call`](https://docs.python.org/2/library/subprocess.html#subprocess.call) returns error code.

> 
> Run the command described by args. Wait for command to complete, then
>  return the returncode attribute.
> 
> 
> 

Trying to iterate over return code (which is an integer) results in `'int' object is not iterable` exception.

To get standard output, you need to use [`subprocess.check_output`](https://docs.python.org/2/library/subprocess.html#subprocess.check_output).

> 
> Run command with arguments and return its output as a byte string.
> 
> 
> 

Since output is already one huge string and does not support lazy file-like protocol, to access separate lines you need to split your string, e.g. by using [`str.splitlines()`](https://docs.python.org/2/library/stdtypes.html#str.splitlines).

> 
> Return a list of the lines in the string, breaking at line boundaries.
>  This method uses the universal newlines approach to splitting lines.
>  Line breaks are not included in the resulting list unless keepends is
>  given and true.
> 
> 
> 

So your code would look like:

```
sum_lines = 0
data = subprocess.call(["nova list"], shell=True)
for line in data.splitlines():
    print line
    sum_lines += 1
print sum_lines

```

To simply count number of lines, `len(data.splitlines())` will also work.
subprocess.call() check it [here](https://docs.python.org/2/library/subprocess.html)

> 
> Run the command described by args. Wait for command to complete, then return the returncode attribute.
> 
> 
> 

It returned an integer not iterable object, therefore you cannot iterate the return value.