Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Dan Strohl Newsgroups: comp.lang.python Subject: RE: Controlling the passing of data Date: Thu, 28 Apr 2016 14:40:01 +0000 Lines: 133 Message-ID: References: <4a16db24a11c4231b3d006bcca10f502@seaexchmbx03.olympus.F5Net.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de qlop83XEscofBmm+7rZnAQpmtGUaWgyjWkb041fZjDYw== Return-Path: 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; 'skip:[ 20': 0.03; 'modify': 0.04; 'guido': 0.05; 'desired.': 0.07; 'differently': 0.07; 'rename': 0.07; 'alter': 0.09; 'comment,': 0.09; 'english,': 0.09; 'imports': 0.09; 'incorrect': 0.09; 'indication': 0.09; 'iterate': 0.09; 'least)': 0.09; 'paragraph,': 0.09; 'suggestions:': 0.09; 'troubleshoot': 0.09; 'python': 0.10; 'assume': 0.11; '"this': 0.13; 'causing': 0.13; 'exception': 0.13; 'thursday,': 0.13; 'suggest': 0.15; 'message-----': 0.15; '"here': 0.16; '2016': 0.16; 'advice:': 0.16; 'already,': 0.16; 'code),': 0.16; 'commented': 0.16; 'dictionaries': 0.16; 'filelist': 0.16; 'loops': 0.16; 'occurence': 0.16; 'optionally': 0.16; 'peters': 0.16; 'posting,': 0.16; 'receive.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'repetitions': 0.16; 'skip:[ 50': 0.16; 'snippets': 0.16; 'stuff,': 0.16; 'to:addr:web.de': 0.16; 'traverse': 0.16; 'wrote:': 0.16; 'string': 0.17; 'passes': 0.18; 'python?': 0.18; 'variable': 0.18; 'to:name:python- list@python.org': 0.20; 'fix': 0.21; 'to:2**1': 0.21; '(by': 0.22; "aren't": 0.22; 'controlling': 0.22; 'referring': 0.22; 'pass': 0.22; 'trying': 0.22; 'code,': 0.23; 'code.': 0.23; 'bit': 0.23; '(or': 0.23; '(you': 0.23; 'errors': 0.23; 'passing': 0.23; 'xml': 0.24; 'header:In-Reply-To:1': 0.24; 'testing': 0.25; "doesn't": 0.26; 'example': 0.26; 'rest': 0.26; 'figure': 0.27; 'separate': 0.27; 'least': 0.27; 'data,': 0.27; 'pieces': 0.27; 'specify': 0.27; 'correct': 0.28; 'function': 0.28; "skip:' 10": 0.28; 'values': 0.28; 'actual': 0.28; 'looks': 0.29; 'dan': 0.29; 'received:192.168.10': 0.29; 'repair': 0.29; 'routine': 0.29; 'sure,': 0.29; 'waters': 0.29; 'starts': 0.29; 'allows': 0.30; 'comments': 0.30; 'url:mailman': 0.30; 'code': 0.30; 'checks': 0.30; 'putting': 0.30; 'writes': 0.30; 'post': 0.31; "can't": 0.32; 'especially': 0.32; 'related': 0.32; 'help,': 0.32; 'possibly': 0.32; 'getting': 0.33; 'point': 0.33; 'problem': 0.33; 'source': 0.33; 'url:python': 0.33; 'done,': 0.33; 'skip:- 10': 0.34; 'url:listinfo': 0.34; 'structure': 0.34; 'file': 0.34; 'handle': 0.34; 'running': 0.34; 'lists': 0.34; 'list': 0.34; 'so,': 0.35; 'on,': 0.35; 'sent:': 0.35; 'clear': 0.35; 'functions.': 0.35; 'question,': 0.35; 'returning': 0.35; 'something': 0.35; 'python-list': 0.66; 'remember,': 0.66; 'here': 0.66; 'results': 0.66; 'email name:python-list': 0.67; 'talking': 0.67; 'choose': 0.68; 'finally': 0.70; 'restore': 0.70; 'race': 0.72; 'car': 0.72; 'saw': 0.77; 'blowing': 0.84; 'clearer': 0.84; 'commenting': 0.84; 'descriptive': 0.84; 'having,': 0.84; 'otten': 0.84; 'points,': 0.84; 'received:192.168.15': 0.84; 'unclear': 0.84; 'working,': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=f5.com; i=@f5.com; q=dns/txt; s=seattle; t=1461854473; x=1493390473; h=from:to:subject:date:message-id:references:in-reply-to: content-transfer-encoding:mime-version; bh=XLX7WeogaT4aF25ND+uxYxnXLh9TOXcTXGg4Ztyl2uk=; b=Sbi0dy1fUWmjeHszZuyCPQ698UOvsnAUx5EmAb/4oSp5RFqw9KE/5tws WzfDNBTUeVceEAC+83sqHNpTv/cJyaUFIdQReuqPsag+Si04j54o1afgs 14aIawm2302uQhLkezSVoNXjvcHEZ61C7ZOcwL1R5Bllqeh7QIkhATKeT U=; X-IronPort-AV: E=Sophos;i="5.24,547,1454976000"; d="scan'208";a="215353339" Thread-Topic: Controlling the passing of data Thread-Index: AQHRoUZuWhIhx+A/60mF+gywqyncuZ+fZP9ugAAEVtA= In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [192.168.15.239] X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <4a16db24a11c4231b3d006bcca10f502@seaexchmbx03.olympus.F5Net.com> X-Mailman-Original-References: Xref: csiph.com comp.lang.python:107793 In addition to Peter's points,=20 - I would suggest breaking out the list comprehensions into standard for lo= ops and/or functions. That makes it easier to read and troubleshoot. (you= can always re-optimize It if needed.) - Peter's point about making things into functions will also help troublesh= ooting. You can better test the data going into and out of the function. = In my code, I will often have the file access and data processing as separa= te functions, then the main routine just calls the function to get data, pa= sses that data to a function that manipulates it, and then pass the results= to a function that writes it out. This allows for much easier testing and= troubleshooting of the individual functions. (sometimes I will reassemble= them into one function when I am done, depending on my needs) More importantly though in terms of your getting help for your problem, the= post is unclear (to me at least) in terms of what you are trying to achiev= e and what isn't working,=20 Try considering the following suggestions: - It is unclear what the problem is that you are having, you say you are tr= ying to do x, and you are having problems in a part after a comment, but no= ne of the comments say "this is breaking". I assume you are talking about = the comment that starts "Here I need to traverse", but don't know for sure,= and even if it is, you don't specify what the problem actually is; are yo= u receiving an exception message (please let us know what it is), is it run= ning, but not doing anything? is it returning incorrect data? or??? - When posting, rather than commenting out code that you aren't using right= now, and code that is working and not related to the problem, I recommend = just deleting them so that people don't have to try to work through it.... = for example, just remove the GetArgs function and just say fileList =3D "/x= ml_dir", and the section at the end that is all commented out, just remove = it. You should just have the minimum needed to replicate the problem. =20 This will also help in troubleshooting, when I have a problem like this, an= d I can't figure out what is going on, I will copy the code to a new file a= nd make a program that will handle a specific set of data, and try to do th= e one thing that is breaking, removing all the rest of the stuff, and test = the results.. so, for example, copy a sample of the xml with a couple of da= ta items into a string var, and have a program that processes that and chec= ks to see if at the end you end up with a list of the right values by print= ing a list rather than muddying the waters with file access, and writing ou= t csv's. (by the way, this is a great time to start working with unit test= ing if you aren't already, it is simple to create this as a test case and y= ou will find that if you start doing testing along the way, the time it tak= es to troubleshoot errors along the way will go down dramatically.) - Be clear at the end what you expect to get, especially if it is not what = you are getting... so, either in the code as a comment, or in a descriptive= paragraph, have a section that said something like: "At the end of the sn= ippet, meetdata, racedata, clubdata, and raceid should be a list of diction= aries with the data from the xml" (or whatever... possibly with an example = of what you would expect). This is even more important if the problem you = are having is that the code is not returning correct data. This may not be= as needed if the code is simply blowing up at line xx, though it would sti= ll help people understand your goal. - For the example at least (you may choose to do differently in your live c= ode), use nice explanatory variable names and don't rename imports, so it w= ould be clearer to say "import pandas", then "frames =3D pandas.DataFrame[]= )". That way the reader doesn't have to keep referring to the imports to f= igure out what is going on. Remember, you are asking a large number of people for help, most of which a= re pretty busy already, so the more you can do to simplify and show the exa= ct problem, the more (and more useful) help you are likely to receive. To = this lists credit, even if you are completely unclear in your question, you= will likely get *something* back, (as you saw with Peters response), but w= hat you get back is more likely to be a general suggestion rather than a sp= ecific fix for your problem. Dan Strohl > -----Original Message----- > From: Python-list [mailto:python-list-bounces+d.strohl=3Df5.com@python.or= g] > On Behalf Of Peter Otten > Sent: Thursday, April 28, 2016 6:40 AM > To: python-list@python.org > Subject: Re: Controlling the passing of data >=20 > Sayth Renshaw wrote: >=20 > > In my file here I needed to traverse and modify the XML file I don't > > want to restore it or put it in a new variable or other format I just > > want to alter it and let it flow onto the list comprehensions as they w= ere. >=20 > That looks like an arbitrary limitation to me. It's a bit like "I want to= repair my > car with this big hammer". >=20 > > In particular here I am taking the id from race and putting it into > > the children of each race called nomination. > > > > I have put a comment above the new code which is causing the difficulty= . >=20 > Your actual problem is drowned in too much source code. Can you restate i= t > in English, optionally with a few small snippets of Python? >=20 > It is not even clear what the code you provide should accomplish once it'= s > running as desired. >=20 > To give at least one code-related advice: You have a few repetitions of t= he > following structure >=20 > > meetattrs =3D ('id', 'venue', 'date', 'rail', 'weather', > > 'trackcondition') >=20 > > meet =3D d('meeting') >=20 > > meetdata =3D [[meet.eq(i).attr(x) > > for x in meetattrs] for i in range(len(meet))] >=20 > You should move the pieces into a function that works for meetings, clubs= , > races, and so on. Finally (If I am repeating myself so be it): the occure= nce of > range(len(something)) in your code is a strong indication that you are no= t > using Python the way Guido intended it. Iterate over the `something` dire= ctly > whenever possible. >=20 > -- > https://mail.python.org/mailman/listinfo/python-list