PLEASE HELP -- TOTALLY NEW TO PYTHON
Mark Lawrence
breamoreboy at yahoo.co.uk
Sat Mar 26 06:39:38 EDT 2016
On 26/03/2016 05:31, 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… Please help
>
> Regards,
> Juan
>
for ind in range(len(list(subgraphs))-1, -1, -1):
However please note that the above is often a code smell in Python. The
usual style is:-
for item in container:
doSomething(item)
Your actual problem would translate into something like:-
for subgraph in reversed(subgraphs):
doSomething(subgraph)
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Python-list
mailing list