Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107799
| Path | csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Dan Strohl <D.Strohl@F5.com> |
| Newsgroups | comp.lang.python |
| Subject | RE: Controlling the passing of data |
| Date | Thu, 28 Apr 2016 15:19:09 +0000 |
| Lines | 142 |
| Message-ID | <mailman.194.1461856753.32212.python-list@python.org> (permalink) |
| References | <afa1ab1d-6d6a-421c-9351-c8805cc5fbea@googlegroups.com> <nft3s8$3ku$1@ger.gmane.org> <mailman.189.1461850832.32212.python-list@python.org> <cf68e844-441c-4498-a730-0c7b08da1ee9@googlegroups.com> <5c94882cb24c441bad13fd122851bd38@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 k6NJKy/ynHJefZnj5O0Xgw1nw/YCHTf3nxX8q4zWMJVw== |
| Return-Path | <prvs=91944878d=D.Strohl@f5.com> |
| 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; 'guido': 0.05; 'attributes': 0.07; 'desired.': 0.07; 'inserts': 0.07; 'meeting,': 0.07; 'meeting.': 0.07; 'csv': 0.09; 'english,': 0.09; 'indication': 0.09; 'inserted': 0.09; 'iterate': 0.09; 'output,': 0.09; 'parsed': 0.09; 'xml.': 0.09; 'python': 0.10; 'output': 0.13; 'thursday,': 0.13; 'intermediate': 0.15; 'message-----': 0.15; '1234': 0.16; '2016': 0.16; 'advice:': 0.16; 'attr': 0.16; 'capability.': 0.16; 'occurence': 0.16; 'optionally': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'repetitions': 0.16; 'skip:[ 50': 0.16; 'snippets': 0.16; 'thought.': 0.16; 'traverse': 0.16; 'variable.': 0.16; 'flexibility': 0.18; 'meetings': 0.18; 'python?': 0.18; 'to:name:python-list@python.org': 0.20; 'to:2**1': 0.21; 'controlling': 0.22; 'parse': 0.22; 'parsing': 0.22; 'simpler': 0.22; 'pass': 0.22; 'code,': 0.23; 'code.': 0.23; 'defined': 0.23; '(you': 0.23; 'insert': 0.23; 'passing': 0.23; 'tables': 0.23; 'second': 0.24; '(this': 0.24; 'xml': 0.24; 'header:In-Reply-To:1': 0.24; 'define': 0.27; 'least': 0.27; 'question': 0.27; 'pieces': 0.27; 'function': 0.28; "skip:' 10": 0.28; 'actual': 0.28; 'correct,': 0.29; 'nominations': 0.29; 'race,': 0.29; 'received:192.168.10': 0.29; 'referencing': 0.29; 'relational': 0.29; 'asked': 0.29; 'classes': 0.30; 'url:mailman': 0.30; 'meeting': 0.30; 'creating': 0.30; 'code': 0.30; 'push': 0.30; 'another': 0.32; 'included': 0.32; 'table': 0.32; 'class': 0.33; 'problem': 0.33; 'source': 0.33; 'url:python': 0.33; 'skip:- 10': 0.34; 'url:listinfo': 0.34; 'changing': 0.34; 'structure': 0.34; 'running': 0.34; 'list': 0.34; 'sent:': 0.35; 'clear': 0.35; 'knowledge': 0.35; 'something': 0.35; 'subject:': 0.35; 'step': 0.36; 'but': 0.36; 'too': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'created': 0.36; 'possible.': 0.36; 'email addr:python.org': 0.36; 'child': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'suggestion': 0.37; 'charset:us-ascii': 0.37; 'wanted': 0.37; 'seem': 0.37; 'wrong': 0.38; 'data': 0.39; 'subject:the': 0.39; "didn't": 0.39; 'from:': 0.39; 'received:192': 0.39; 'rather': 0.39; 'skip:x 10': 0.40; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'your': 0.60; 'determine': 0.61; 'provide': 0.61; 'identify': 0.61; 'back': 0.62; 'skip:n 10': 0.62; 'information': 0.63; 'python-list': 0.66; 'email name:python-list': 0.67; 'direct': 0.68; 'finally': 0.70; 'race': 0.72; 'lack': 0.76; '7:00': 0.84; 'received:192.168.15': 0.84; 'relate': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=simple/simple; d=f5.com; i=@f5.com; q=dns/txt; s=seattle; t=1461856752; x=1493392752; h=from:to:subject:date:message-id:references:in-reply-to: content-transfer-encoding:mime-version; bh=Zw+RaH4JQWmNZkQt0bptupgwjwXYDCeCsS61D275O9s=; b=KLnTI0lO6on9MlvJeI3A/WuoG4UdqvmRnlhIpDb7tsdXakE4uCEP/zmF VoOEUFhOvBeLodt595cYyDSTJJXumhhA91Z5QHd63PRsAD6ZLVjIF781I a4wMiKPP+qpZTQR+f52O/NT4Pr2g7v4wkEd9pKDdOT6yveLaEs3Lo0bv4 I=; |
| X-IronPort-AV | E=Sophos;i="5.24,547,1454976000"; d="scan'208";a="215363177" |
| Thread-Topic | Controlling the passing of data |
| Thread-Index | AQHRoUZuWhIhx+A/60mF+gywqyncuZ+fZP9ugAAFc6GAABIHoA== |
| In-Reply-To | <cf68e844-441c-4498-a730-0c7b08da1ee9@googlegroups.com> |
| 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 <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> |
| X-Mailman-Original-Message-ID | <5c94882cb24c441bad13fd122851bd38@seaexchmbx03.olympus.F5Net.com> |
| X-Mailman-Original-References | <afa1ab1d-6d6a-421c-9351-c8805cc5fbea@googlegroups.com> <nft3s8$3ku$1@ger.gmane.org> <mailman.189.1461850832.32212.python-list@python.org> <cf68e844-441c-4498-a730-0c7b08da1ee9@googlegroups.com> |
| Xref | csiph.com comp.lang.python:107799 |
Show key headers only | View raw
If I am reading this correctly... you have something like (you will have to excuse my lack of knowledge about what kinds of information these actually are):
<race id=1>
<nomination>1234</nomination>
<meeting>first</meeting>
</race>
<race id=2>
<nomination>5678</nomination>
<meeting>second</meeting>
</race>
And you want something like:
nominations = [(1,1234), (2,5678)]
meetings = [(1,'first'),(2,'second')]
if that is correct, my suggestion is to do something like (this is psudeo code, I didn't look up the exact calls to use):
nomination_list = []
meeting_list = []
for race_element in xml_file('race'):
id = race_element.get_attr('id')
for nomination_element in race_element('nomination'):
nomination = nomination_element.get_text()
nomination_list.append((id, nomination))
for meeting_element in race_element('meeting'):
meeting = meeting_element.get_text()
meeting_list.append((id, meeting))
> -----Original Message-----
> From: Python-list [mailto:python-list-bounces+d.strohl=f5.com@python.org]
> On Behalf Of Sayth Renshaw
> Sent: Thursday, April 28, 2016 7:00 AM
> To: python-list@python.org
> Subject: Re: Controlling the passing of data
>
>
> >
> > Your actual problem is drowned in too much source code. Can you
> > restate it in English, optionally with a few small snippets of Python?
> >
> > It is not even clear what the code you provide should accomplish once
> > it's running as desired.
> >
> > To give at least one code-related advice: You have a few repetitions
> > of the following structure
> >
> > > meetattrs = ('id', 'venue', 'date', 'rail', 'weather',
> > > 'trackcondition')
> >
> > > meet = d('meeting')
> >
> > > meetdata = [[meet.eq(i).attr(x)
> > > for x in meetattrs] for i in range(len(meet))]
> >
> > 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 occurence of range(len(something)) in your code is a strong
> > indication that you are not using Python the way Guido intended it.
> > Iterate over the `something` directly whenever possible.
>
> Hi Peter
>
> > meetattrs = ('id', 'venue', 'date', 'rail', 'weather',
> > 'trackcondition')
>
> is created to define a list of attr in the XML rather than referencing each attr
> individually I create a list and pass it into
>
> > meetdata = [[meet.eq(i).attr(x)
> > > for x in meetattrs] for i in range(len(meet))]
>
> This list comprehension reads the XML attr by attr using meet = d('meeting')
> as the call to pyquery to locate the class in the XML and identify the attr's.
>
> I do apologise for the lack of output, I asked a question about parsing that I
> always seem to get wrong over think and then find the solution simpler than
> I thought.
>
> The output is 4 tables of the class and selected attributes eg meetattrs = ('id',
> 'venue', 'date', 'rail', 'weather', 'trackcondition') from the meeting class of the
> XML.
>
> In order to give flexibility and keep the relational nature they have defined in
> the table I found when exporting the nominations section via pandas to csv
> that i had no way to determine which id belonged to each race that is there
> was no race_id in the nominations to relate back to the race, and also no
> meeting id in the raceid to relate it back to the meeting.
>
>
> So I wanted to traverse all the classes Meeting, Race and Nomination and
> insert the id of the class into its direct children only and since there were
> many races a meeting and many nomnations a race I need to ensure that it is
> the direct children only.
>
> It was otherwise working as parsed output in code supplied using to push to
> pandas and use its csv write capability.
>
> So I inserted
>
> for race_el in d('race'):
> race = pq(race_el)
> race_id = race.attr('id')
>
> for nom_el in race.items('nomination'):
> res.append((pq(nom_el).attr('raceid', race_id)))
>
> which traverses and inserts the race_id into the child nominations. However,
> my boggles is how to pass this to the list comprehension that was working
> without changing the data from XML or creating another intermediate step
> and variable. Just to parse it as it was but with the extra included race_id.
>
>
> Thanks
>
> Sayth
> --
> https://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Controlling the passing of data Sayth Renshaw <flebber.crue@gmail.com> - 2016-04-28 05:02 -0700
Re: Controlling the passing of data Peter Otten <__peter__@web.de> - 2016-04-28 15:40 +0200
Re: Controlling the passing of data Sayth Renshaw <flebber.crue@gmail.com> - 2016-04-28 06:59 -0700
RE: Controlling the passing of data Dan Strohl <D.Strohl@F5.com> - 2016-04-28 15:19 +0000
Re: Controlling the passing of data Sayth Renshaw <flebber.crue@gmail.com> - 2016-04-28 18:49 -0700
Re: Controlling the passing of data Peter Otten <__peter__@web.de> - 2016-04-29 13:26 +0200
Re: Controlling the passing of data Sayth Renshaw <flebber.crue@gmail.com> - 2016-04-29 06:17 -0700
Re: Controlling the passing of data Peter Otten <__peter__@web.de> - 2016-04-29 13:36 +0200
RE: Controlling the passing of data Dan Strohl <D.Strohl@F5.com> - 2016-04-28 14:40 +0000
Re: Controlling the passing of data Rustom Mody <rustompmody@gmail.com> - 2016-04-28 07:52 -0700
csiph-web