Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71554

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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'argument': 0.05; 'debug': 0.07; 'lines,': 0.07; 'linux,': 0.07; 'problem?': 0.07; 'subject:file': 0.07; 'subject:help': 0.08; 'assuming': 0.09; 'attributes': 0.09; 'classes.': 0.09; 'exception.': 0.09; 'method,': 0.09; 'next,': 0.09; 'obsolete': 0.09; 'subject:xml': 0.09; "they've": 0.09; 'thus,': 0.09; 'whatever.': 0.09; 'python': 0.11; '2.7': 0.14; '89,': 0.16; 'attribute,': 0.16; 'bug,': 0.16; 'commented': 0.16; 'definition.': 0.16; 'did,': 0.16; 'indexerror:': 0.16; 'integer,': 0.16; 'old-style': 0.16; 'statements,': 0.16; 'subject: \n ': 0.16; 'subject:XML': 0.16; 'subject:after': 0.16; 'exception': 0.16; 'files.': 0.16; 'index': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'all,': 0.19; 'trying': 0.19; 'file,': 0.19; 'stack': 0.19; 'written': 0.21; 'help.': 0.21; 'code,': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'integer': 0.24; 'file.': 0.24; 'source': 0.25; 'class.': 0.26; 'first,': 0.26; 'mention': 0.26; 'shown': 0.26; 'skip:" 30': 0.26; 'least': 0.26; 'asking': 0.27; 'certain': 0.27; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'code': 0.31; 'lines': 0.31; 'posting': 0.31; 'about.': 0.31; 'apparently': 0.31; 'comments,': 0.31; 'object.': 0.31; 'occurs': 0.31; 'file': 0.32; 'class': 0.32; 'supposed': 0.32; 'another': 0.32; '(most': 0.33; 'subject:from': 0.34; 'could': 0.34; 'problem': 0.35; "can't": 0.35; 'classes': 0.35; 'problem.': 0.35; 'something': 0.35; 'hundreds': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'version': 0.36; 'edge': 0.36; 'subject:data': 0.36; 'method': 0.36; 'thanks': 0.36; 'should': 0.36; 'so,': 0.37; 'too': 0.37; 'list': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'skip:u 10': 0.60; 'easy': 0.60; 'tell': 0.60; 'took': 0.61; 'range': 0.61; "you're": 0.61; 'complete': 0.62; 'email addr:gmail.com': 0.63; 'name': 0.63; 'real': 0.63; 'such': 0.63; 'field': 0.63; 'happen': 0.63; 'myself': 0.63; 'skip:n 10': 0.64; 'subject:Need': 0.64; 'more': 0.64; 'received:74.208': 0.68; 'study': 0.69; 'obvious': 0.74; 'received:74.208.4.194': 0.84; 'safer': 0.84; 'destination': 0.91; 'yourself,': 0.95
Date Wed, 14 May 2014 03:32:56 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Need help to write data onto an XML file after reading data from another xml file
References <2c8cb313-50f6-439b-a979-bd320a2c7b2c@googlegroups.com> <e5739cae-7fe5-4f63-95ec-cad7ce5190d8@googlegroups.com>
In-Reply-To <e5739cae-7fe5-4f63-95ec-cad7ce5190d8@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:mNQHn7BnqGG8zWuRtMiLViYm1lsvVgNc5scRi8wYneM NzZm3Xej3v4hywKdvhhvZRN5bODTus2es8X8G9NZv+os4h7sw2 Su4jp1jw/WchNZSr78yBixA6wXoZqUknP+LowmRG1p2bzw4+i6 5PABWmkSLjznsdBaKrnNLs2hzx1ObLwQAEqfi+fX3qAdl7BzaD lqnh/s8XOSG/bvDXRNEYqok1tljJkmL9pOyC32wFa5e9kAr2Ig uguQ3ZGkkncoBJNg3cZWdLz8vkmfwAN7A/BlorY01oh4RWaWts ylprHaXm6br3PCab9KTJJ3ufH7A6SvVVwTLpnJxMsE8bWhKx6X hedMVEJtvsxinaGz9kc8=
X-Mailman-Approved-At Wed, 14 May 2014 14:56:46 +0200
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10004.1400072207.18130.python-list@python.org> (permalink)
Lines 70
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1400072207 news.xs4all.nl 2859 [2001:888:2000:d::a6]:39004
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:71554

Show key headers only | View raw


On 05/14/2014 02:49 AM, varun7rs@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Need help to write data onto an XML file after reading data from another xml file varun7rs@gmail.com - 2014-05-13 07:31 -0700
  Re: Need help to write data onto an XML file after reading data from another xml file Dave Angel <d@davea.name> - 2014-05-13 22:09 -0400
  Re: Need help to write data onto an XML file after reading data from another xml file varun7rs@gmail.com - 2014-05-13 23:49 -0700
    Re: Need help to write data onto an XML file after reading data from another xml file Dave Angel <davea@davea.name> - 2014-05-14 03:32 -0400
      Re: Need help to write data onto an XML file after reading data from another xml file varun7rs@gmail.com - 2014-05-14 06:42 -0700
        Re: Need help to write data onto an XML file after reading data from another xml file Chris Angelico <rosuav@gmail.com> - 2014-05-14 23:49 +1000

csiph-web