Need help to write data onto an XML file after reading data from another xml file

Dave Angel davea at davea.name
Wed May 14 03:32:56 EDT 2014


On 05/14/2014 02:49 AM, varun7rs at gmail.com wrote:
> I try to add an edge with the source id and destination id over a loop but this is the error I am getting. And the range for the for addEdge is something I have no clue about.
>
> python export.py --output topology.xml --xml germany50.xml
> Traceback (most recent call last):
>    File "export.py", line 239, in <module>
>      main(sys.argv[1:])
>    File "export.py", line 234, in main
>      network.addEdge( PHY_LINKS( j , sourcen, destnn, sid, did, cap_bdw) )
>    File "/home/srva/Approach_Read.py", line 89, in addEdge
>      self.nodes[ edge.SourceID ].addInEdge( edge )
> IndexError: list index out of range
>

Thanks for posting a complete stack trace, it can be a real help.  You 
still have not shown us the source code.  Did you write it yourself, or 
are you just trying to debug something written by someone else?

In particular, the exception occurs in Approach_Read.py.  Is that your 
file, and can you edit it to ferret out the problem?  Do you know what 
attributes are supposed to be of what types?

I peaked;  I actually took a look at your dropbox files.  So I have some 
comments, though they may not help debug the problem.  After all, there 
are hundreds of lines of code,

First, you don't mention the Python version nor the OS you're using. 
Indirectly, I can surmise Python 2.7 and Linux, but it's much safer to 
declare such things in the problem descrition.

Assuming 2.x, you're using old-style classes.  While that might not be a 
bug, they've been obsolete for at least a decade.  You need to derive 
each of your classes from object.  So, you should have for example:

class CplexSolver(object):

next, you have way too few comments.  I can't even tell why you put 
certain classes and functions in one file, versus others in another file.

Next, you don't follow Pep8, or any other reasonable standard, for 
naming.  Thus, I can't tell readily whether a particular name is a class 
name, an attribute, a method, or whatever.  If the code were smaller, I 
might be willing to work it out, and make myself a crossref, but that's 
why you should simplify a problem you're asking for help with.  If the 
code is 700 lines, few people are going to be willing to study it unless 
it's very well commented and easy to follow.

You have a name PHY_NETWORK, which being all caps would indicate it's a 
const, but instead it's actually a class.  It has a method addEdge(), 
which takes an argument edge.  But it's not obvious to me what class 
that is, so I could look up its definition.  If you don't know either, 
you could add a print type(edge) to that method, and see what gets 
printed just before it gets the exception.

That field might happen to be of type PHY_LINKS, in which case we see 
the initializer has the line
    self.SourceID = SourceID

Unfortunately, we don't know what class that's supposed to be.  You're 
using it like it's an integer, and the integer is apparently outside the 
range of the list PHY_NETWORK.nodes

So you could add a few more print statements, find out the len() of 
nodes, and the value of SourceID.




-- 
DaveA



More information about the Python-list mailing list