PLEASE HELP -- TOTALLY NEW TO PYTHON

Steven D'Aprano steve at pearwood.info
Sat Mar 26 07:52:19 EDT 2016


On Sat, 26 Mar 2016 04:31 pm, Juan Dent wrote:

> 
> I am trying to run ‘python cppdep.py’ but get the following:
> 
>
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> analyzing dependencies among all components ...
> Traceback (most recent call last):
>   File "cppdep.py", line 675, in <module>
>     main()
>   File "cppdep.py", line 643, in main
>     calculate_graph(digraph)
>   File "cppdep.py", line 570, in calculate_graph
>     (cycles, dict_node2cycle) = make_DAG(digraph, key_node)
>   File "/Users/juandent/Downloads/cppdep-master/networkx_ext.py", line 79,
>   in make_DAG
>     for ind in range(len(subgraphs)-1, -1, -1):
> TypeError: object of type 'generator' has no len()
> 
> 
> Please, I know no python and am in a hurry to get this working… 

Left your homework for the very last day, did you? I'm sorry that you are in
a hurry, but that's not our problem.

Look at the last two lines of the error traceback. The second last tells you
the line that failed:

    for ind in range(len(subgraphs)-1, -1, -1):

and the last line tells you the error:

    TypeError: object of type 'generator' has no len()

The error tells you that "subgraphs" is a "generator", not a list. So you
have two choices:

- you can change "subgraphs" to be a list;

- or you can change the for-loop to not need the length of subgraphs, or the
index.


The smaller change would probably be the first, changing subgraphs. But the
better change would probably be to change the for-loop.




-- 
Steven




More information about the Python-list mailing list