- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我之前发布了一个question on SO其中包含允许测试的缩写示例 XML,我编辑了 XML 的重复内容以允许发布它。
我发布的 XML 插入是
<meeting id="42736" barriertrial="0" venue="Rosehill Gardens" date="2016-03-19T00:00:00" gearchanges="-1" stewardsreport="-1" gearlist="-1" racebook="0" postracestewards="0" meetingtype="TAB" rail="Timing - Electronic : Rail - +2m" weather="Fine " trackcondition="Good" nomsdeadline="2016-03-14T11:00:00" weightsdeadline="2016-03-15T16:00:00" acceptdeadline="2016-03-16T09:00:00" jockeydeadline="2016-03-16T12:00:00">
<club abbrevname="Australian Turf Club" code="56398" associationclass="1" website="http://" />
<race id="213262" number="1" nomnumber="7" division="0" name="NATHAN'S FAMOUS EPONA STAKES" mediumname="EPONA" shortname="EPONA STAKES" stage="Results" distance="1900" minweight="0" raisedweight="0" class="~ " age="3U " grade="0" weightcondition="SWP " trophy="1000" owner="1000" trainer="0" jockey="0" strapper="0" totalprize="150000" first="90000" second="30000" third="15000" fourth="7500" fifth="3000" time="2016-03-19T12:40:00" bonustype=" " nomsfee="0" acceptfee="0" trackcondition="Good " timingmethod="Electronic" fastesttime="1-56.83 " sectionaltime="600/35.3 " formavailable="0" racebookprize="Of $150000 and trophies of $1000. First $90000 and trophies of $1000 to owner, second $30000, third $15000, fourth $7500, fifth $3000, sixth $1500, seventh $1500, eighth $1500">
<condition line="1">Of $150000 and trophies of $1000. First $90000 and trophies of $1000 to owner, second $30000, third $15000, fourth $7500, fifth $3000, sixth $1500, seventh $1500, eighth $1500</condition>
<condition line="3">No class restriction, Set Weights plus Penalties, For Three-Years-Old and Upwards, Fillies and Mares, (Group 3)</condition>
<condition line="5">No Allowances for apprentices. Field Limit: 14 + 4 EM</condition>
<nomination number="4" saddlecloth="4" horse="Vergara" id="171115" idnumber="" regnumber="" blinkers="1" trainernumber="38701" trainersurname="Cummings" trainerfirstname="Anthony" trainertrack="Randwick" rsbtrainername="Anthony Cummings" jockeynumber="86876" jockeysurname="McDonald" jockeyfirstname="James" barrier="7" weight="55" rating="93" description="B M 5 Snippetson x Graces Spirit (Flying Spur)" colours="Yellow, Red Epaulettes And Cap" owners="Anthony Cummings Thoroughbreds Pty Ltd Syndicate (Mgrs: A & B Cummings) & P C Racing Investments Syndicate (Mgr: P J Carroll) " dob="2010-10-07T00:00:00" age="6" sex="M" career="30-7-4-2 $295445.00" thistrack="6-1-1-0 $90500.00" thisdistance="0-0-0-0" goodtrack="17-3-2-2 $101440.00" heavytrack="5-0-1-0 $20200.00" slowtrack="" deadtrack="" fasttrack="0-0-0-0" firstup="7-2-1-2 $108340.00" secondup="7-1-1-0 $43200.00" mindistancewin="0" maxdistancewin="0" finished="1" weightvariation="0" variedweight="55" decimalmargin="0.00" penalty="0" pricestarting="$12" sectional200="0" sectional400="0" sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
<nomination number="2" saddlecloth="2" horse="Heavens Above" id="187674" idnumber="" regnumber="" blinkers="0" trainernumber="736" trainersurname="Martin" trainerfirstname="Tim" trainertrack="Rosehill" rsbtrainername="Tim Martin" jockeynumber="46930" jockeysurname="Angland" jockeyfirstname="Tye" barrier="6" weight="56" rating="88" description="B M 4 Street Cry(IRE) x Reggie(NZ) (Germano(GB))" colours="Yellow, Green Chevrons, Striped Cap" owners="President Bloodstock Pty Ltd (Mgr: R C Kemister)" dob="2011-08-12T00:00:00" age="5" sex="M" career="12-3-3-4 $271520.00" thistrack="4-0-3-0 $41425.00" thisdistance="0-0-0-0" goodtrack="10-2-2-4 $214845.00" heavytrack="0-0-0-0" slowtrack="" deadtrack="" fasttrack="0-0-0-0" firstup="2-0-1-1 $20710.00" secondup="2-0-2-0 $24675.00" mindistancewin="0" maxdistancewin="0" finished="2" weightvariation="0" variedweight="56" decimalmargin="0.20" penalty="0" pricestarting="$3.80F" sectional200="0" sectional400="0" sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
<nomination number="6" saddlecloth="6" horse="Sweet Fire" id="184732" idnumber="" regnumber="" blinkers="0" trainernumber="681" trainersurname="Waller" trainerfirstname="Chris" trainertrack="Rosehill" rsbtrainername="Chris Waller" jockeynumber="51661" jockeysurname="Berry" jockeyfirstname="Tommy" barrier="5" weight="54" rating="85" description="BR M 4 Shamardal(USA) x Zarinia(IRE) (Intikhab(USA))" colours="Lilac And White Halves, Black Cap" owners="E J Lucas " dob="2011-09-25T00:00:00" age="5" sex="M" career="15-4-2-2 $212750.00" thistrack="6-1-1-1 $56690.00" thisdistance="0-0-0-0" goodtrack="9-2-1-2 $120395.00" heavytrack="1-0-0-0 $450.00" slowtrack="" deadtrack="" fasttrack="0-0-0-0" firstup="3-0-0-0 $1900.00" secondup="3-1-1-0 $42200.00" mindistancewin="0" maxdistancewin="0" finished="3" weightvariation="0" variedweight="54" decimalmargin="0.50" penalty="0" pricestarting="$7" sectional200="0" sectional400="0" sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
<nomination number="7" saddlecloth="7" horse="Alegria" id="181928" idnumber="" regnumber="" blinkers="1" trainernumber="235" trainersurname="O'Shea" trainerfirstname="John" trainertrack="Agnes Banks/Hawkesbury" rsbtrainername="John O'Shea" jockeynumber="40275" jockeysurname="Clark" jockeyfirstname="Tim" barrier="1" weight="54" rating="81" description="B M 4 Medaglia D'oro(USA) x Pure Joy (Fusaichi Pegasus(USA))" colours="Royal Blue" owners="Godolphin" dob="2011-10-06T00:00:00" age="5" sex="M" career="12-3-1-5 $216850.00" thistrack="4-1-0-2 $89600.00" thisdistance="0-0-0-0" goodtrack="5-1-1-3 $87575.00" heavytrack="4-2-0-1 $114275.00" slowtrack="" deadtrack="" fasttrack="0-0-0-0" firstup="3-2-0-1 $80500.00" secondup="3-0-0-2 $20850.00" mindistancewin="0" maxdistancewin="0" finished="4" weightvariation="0" variedweight="54" decimalmargin="0.70" penalty="0" pricestarting="$8.50" sectional200="0" sectional400="0" sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
<nomination number="11" saddlecloth="11" horse="Piamimi" id="158914" idnumber="" regnumber="" blinkers="0" trainernumber="773" trainersurname="Bennett" trainerfirstname="Greg" trainertrack="Scone" rsbtrainername="Greg Bennett" jockeynumber="48503" jockeysurname="Williams" jockeyfirstname="Craig" barrier="8" weight="54" rating="75" description="B OR BR M 6 Not a Single Doubt x Blurrta(NZ) (Bahhare(USA))" colours="Yellow, Dark Blue Diamonds, Striped Sleeves And Cap" owners="Dr M Wylie, K Kenny, J Canning, M Mcfayden, B Hyde & P Toubji " dob="2009-08-23T00:00:00" age="7" sex="M" career="35-6-4-3 $170275.00" thistrack="2-0-0-0 $5150.00" thisdistance="2-0-0-0 $900.00" goodtrack="25-3-2-2 $78640.00" heavytrack="4-1-1-1 $24510.00" slowtrack="" deadtrack="" fasttrack="0-0-0-0" firstup="8-1-3-0 $27375.00" secondup="8-1-0-2 $32645.00" mindistancewin="0" maxdistancewin="0" finished="5" weightvariation="0" variedweight="54" decimalmargin="1.10" penalty="0" pricestarting="$41" sectional200="0" sectional400="0" sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
<nomination number="10" saddlecloth="10" horse="Blendwell" id="171408" idnumber="" regnumber="" blinkers="0" trainernumber="78024" trainersurname="Moody" trainerfirstname="Peter G" trainertrack="Warwick Farm" rsbtrainername="Peter G Moody" jockeynumber="85036" jockeysurname="Lane" jockeyfirstname="Damian" barrier="10" weight="54" rating="78" description="B M 5 Hard Spun(USA) x Bridie Belle(NZ) (Al Akbar)" colours="Tartan, Red Sash And Armbands" owners="D & M Esplin Pty Ltd (Mgr: Mrs M E Esplin)" dob="2010-10-06T00:00:00" age="6" sex="M" career="17-4-3-4 $107845.00" thistrack="0-0-0-0" thisdistance="0-0-0-0" goodtrack="8-0-1-2 $25135.00" heavytrack="2-2-0-0 $42000.00" slowtrack="" deadtrack="" fasttrack="0-0-0-0" firstup="6-0-0-3 $8835.00" secondup="3-1-0-1 $20050.00" mindistancewin="0" maxdistancewin="0" finished="6" weightvariation="0" variedweight="54" decimalmargin="1.20" penalty="0" pricestarting="$17" sectional200="0" sectional400="0" sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
<nomination number="3" saddlecloth="3" horse="Adorabeel (NZ)" id="166836" idnumber="" regnumber="" blinkers="0" trainernumber="1942" trainersurname="Pride" trainerfirstname="Joseph" trainertrack="Warwick Farm" rsbtrainername="Joseph Pride" jockeynumber="86280" jockeysurname="Clipperton" jockeyfirstname="Sam" barrier="9" weight="56" rating="86" description="BR OR BLK M 6 Savabeel x Plaza Doree(FR) (Saumarez(GB))" colours="Maroon, White Crossed Sashes, Yellow Armbands And Cap" owners="Mystery Downs (Mgr: F W Cook)" dob="2009-09-11T00:00:00" age="7" sex="M" career="34-6-5-4 $281810.00" thistrack="11-1-2-1 $105750.00" thisdistance="2-0-0-0 $3800.00" goodtrack="24-3-3-1 $203910.00" heavytrack="0-0-0-0" slowtrack="" deadtrack="" fasttrack="0-0-0-0" firstup="7-1-1-1 $28650.00" secondup="7-0-2-1 $25050.00" mindistancewin="0" maxdistancewin="0" finished="7" weightvariation="0" variedweight="56" decimalmargin="2.30" penalty="0" pricestarting="$13" sectional200="0" sectional400="0" sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
<nomination number="8" saddlecloth="8" horse="Mary Lou" id="172933" idnumber="" regnumber="" blinkers="1" trainernumber="38701" trainersurname="Cummings" trainerfirstname="Anthony" trainertrack="Randwick" rsbtrainername="Anthony Cummings" jockeynumber="86596" jockeysurname="Collett" jockeyfirstname="Jason" barrier="11" weight="54" rating="80" description="B M 5 Fastnet Rock x Miss Alabama(NZ) (Woodman(USA))" colours="Red, Black Diagonal Stripes And Armbands, Quartered Cap" owners="E-Thoroughbred (Mgr: A W & M G Bott) & Evergreen Rich (Mgr: A W Bott, P K Siu, M Siu & E Siu)" dob="2010-09-18T00:00:00" age="6" sex="M" career="18-3-3-4 $156860.00" thistrack="3-1-0-1 $33375.00" thisdistance="1-1-0-0 $17250.00" goodtrack="14-3-2-4 $130335.00" heavytrack="2-0-0-0 $525.00" slowtrack="" deadtrack="" fasttrack="0-0-0-0" firstup="3-1-0-0 $31125.00" secondup="3-0-1-2 $25100.00" mindistancewin="0" maxdistancewin="0" finished="8" weightvariation="0" variedweight="54" decimalmargin="2.70" penalty="0" pricestarting="$18" sectional200="0" sectional400="0" sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
<nomination number="9" saddlecloth="9" horse="Skyline Blush" id="182533" idnumber="" regnumber="" blinkers="1" trainernumber="38701" trainersurname="Cummings" trainerfirstname="Anthony" trainertrack="Randwick" rsbtrainername="Anthony Cummings" jockeynumber="1472" jockeysurname="McEvoy" jockeyfirstname="Kerrin" barrier="4" weight="54" rating="80" description="B M 4 Northern Meteor x Cara Y Cruz(USA) (King of Kings(IRE))" colours="Red, Black Stripes" owners="Gooree Stud (E M Cojuangco & M C Cummings)" dob="2011-10-29T00:00:00" age="5" sex="M" career="14-5-0-2 $204190.00" thistrack="4-1-0-1 $52225.00" thisdistance="2-1-0-1 $41375.00" goodtrack="7-0-0-1 $19535.00" heavytrack="4-2-0-1 $111125.00" slowtrack="" deadtrack="" fasttrack="0-0-0-0" firstup="3-1-0-0 $21125.00" secondup="3-0-0-1 $12460.00" mindistancewin="0" maxdistancewin="0" finished="9" weightvariation="0" variedweight="54" decimalmargin="3.10" penalty="0" pricestarting="$9.50" sectional200="0" sectional400="0" sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
<nomination number="5" saddlecloth="5" horse="All Cerise" id="171801" idnumber="" regnumber="" blinkers="0" trainernumber="681" trainersurname="Waller" trainerfirstname="Chris" trainertrack="Rosehill" rsbtrainername="Chris Waller" jockeynumber="86721" jockeysurname="Dunn" jockeyfirstname="Dwayne" barrier="3" weight="54" rating="92" description="B M 5 Redoute's Choice x Trick Taker(USA) (Capote(USA))" colours="Purple, White Hoops, Black Seams, Purple And White Quartered Cap" owners="Woppitt Bloodstock (Mgr: Mrs D N Kepitis)" dob="2010-11-05T00:00:00" age="6" sex="M" career="28-6-3-3 $349890.00" thistrack="10-1-1-1 $111750.00" thisdistance="0-0-0-0" goodtrack="21-6-2-3 $327690.00" heavytrack="2-0-0-0 $450.00" slowtrack="" deadtrack="" fasttrack="0-0-0-0" firstup="7-1-0-2 $45790.00" secondup="4-1-0-0 $71200.00" mindistancewin="0" maxdistancewin="0" finished="10" weightvariation="0" variedweight="54" decimalmargin="4.10" penalty="0" pricestarting="$6" sectional200="0" sectional400="0" sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
<nomination number="1" saddlecloth="1" horse="Gust of Wind (NZ)" id="181079" idnumber="" regnumber="" blinkers="1" trainernumber="41655" trainersurname="Sargent" trainerfirstname="John" trainertrack="Randwick" rsbtrainername="John Sargent" jockeynumber="84015" jockeysurname="Avdulla" jockeyfirstname="Brenton" barrier="2" weight="59" rating="106" description="B M 4 Darci Brahma(NZ) x Starrystarrynight(IRE) (Sadler's Wells(USA))" colours="Yellow, White Checked Sash, Checked Sleeves And Cap" owners="Go Bloodstock (Mgr: Sir O G Glenn)" dob="2011-09-07T00:00:00" age="5" sex="M" career="12-3-0-0 $974900.00" thistrack="0-0-0-0" thisdistance="0-0-0-0" goodtrack="10-2-0-0 $279150.00" heavytrack="0-0-0-0" slowtrack="" deadtrack="" fasttrack="0-0-0-0" firstup="4-1-0-0 $8900.00" secondup="3-1-0-0 $20250.00" mindistancewin="0" maxdistancewin="0" finished="11" weightvariation="0" variedweight="59" decimalmargin="7.40" penalty="0" pricestarting="$15" sectional200="0" sectional400="0" sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
</race>
</meeting>
该问题的答案适用于示例代码。
import xmltodict
with open('20160319RHIL0_edit.xml') as f:
my = xmltodict.parse(f.read())
for condition in my['meeting']['race']['condition']:
print(condition["@line"])
但是,然后用于此处引用的完整 XML,粘贴失败并出现类型错误
with open('20160319RHIL0.xml') as f:
my = xmltodict.parse(f.read())
for condition in my['meeting']['race']['condition']:
print(condition["@line"])
runfile('C:/Users/Sayth/.spyder2-py3/temp.py', wdir='C:/Users/Sayth/Documents')
Traceback (most recent call last):
File "<ipython-input-2-bbaf7572afd1>", line 1, in <module>
runfile('C:/Users/Sayth/.spyder2-py3/temp.py', wdir='C:/Users/Sayth/Documents')
File "C:\Users\Sayth\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "C:\Users\Sayth\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 88, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "C:/Users/Sayth/.spyder2-py3/temp.py", line 13, in <module>
for condition in my['meeting']['race']['condition']:
TypeError: list indices must be integers or slices, not str
XML 结构有何不同导致结果出现这种差异?
最佳答案
由于存在多个races
和多个conditions
,它们表示为Python列表,因此您必须循环遍历它们:
for race in my['meeting']['race']:
for condition in race['condition']:
print(condition["@line"])
为我处理您的真实 XML 数据。打印:
1
3
5
1
...
2
3
5
关于python - 相同结构的示例 XML 的解析方式与完整 XML 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36428053/
我一直在阅读有关汇编函数的内容,但对于是使用进入和退出还是仅使用调用/返回指令来快速执行,我感到很困惑。一种方式快而另一种方式更小吗?例如,在不内联函数的情况下,在汇编中执行此操作的最快(stdcal
我正在处理一个元组列表,如下所示: res = [('stori', 'JJ'), ('man', 'NN'), ('unnatur', 'JJ'), ('feel', 'NN'), ('pig',
最近我一直在做很多网络或 IO 绑定(bind)操作,使用线程有助于加快代码速度。我注意到我一直在一遍又一遍地编写这样的代码: threads = [] for machine, user, data
假设我有一个名为 user_stats 的资源,其中包含用户拥有的帖子、评论、喜欢和关注者的数量。是否有一种 RESTful 方式只询问该统计数据的一部分(即,对于 user_stats/3,请告诉我
我有一个简单的 api,它的工作原理是这样的: 用户创建一个请求 ( POST /requests ) 另一个用户检索所有请求 ( GET /requests ) 然后向请求添加报价 ( POST /
考虑以下 CDK Python 中的示例(对于这个问题,不需要 AWS 知识,这应该对基本上任何构建器模式都有效,我只是在这个示例中使用 CDK,因为我使用这个库遇到了这个问题。): from aws
Scala 中管理对象池的首选方法是什么? 我需要单线程创建和删除大规模对象(不需要同步)。在 C++ 中,我使用了静态对象数组。 在 Scala 中处理它的惯用和有效方法是什么? 最佳答案 我会把它
我有一个带有一些内置方法的类。这是该类的抽象示例: class Foo: def __init__(self): self.a = 0 self.b = 0
返回和检查方法执行的 Pythonic 方式 我目前在 python 代码中使用 golang 编码风格,决定移动 pythonic 方式 例子: import sys from typing imp
我正在开发一个 RESTful API。其中一个 URL 允许调用者通过 id 请求特定人员的记录。 返回该 id 不存在的记录的常规值是什么?服务器是否应该发回一个空对象或者一个 404,或者其他什
我正在使用 pathlib.Path() 检查文件是否存在,并使用 rasterio 将其作为图像打开. filename = pathlib.Path("./my_file-name.tif") 但
我正在寻找一种 Pythonic 方式来从列表和字典创建嵌套字典。以下两个语句产生相同的结果: a = [3, 4] b = {'a': 1, 'b': 2} c = dict(zip(b, a))
我有一个正在操裁剪理设备的脚本。设备有时会发生物理故障,当它发生时,我想重置设备并继续执行脚本。我有这个: while True: do_device_control() device
做组合别名的最pythonic和正确的方法是什么? 这是一个假设的场景: class House: def cleanup(self, arg1, arg2, kwarg1=False):
我正在开发一个小型客户端服务器程序来收集订单。我想以“REST(ful)方式”来做到这一点。 我想做的是: 收集所有订单行(产品和数量)并将完整订单发送到服务器 目前我看到有两种选择: 将每个订单行发
我知道在 Groovy 中您可以使用字符串调用类/对象上的方法。例如: Foo."get"(1) /* or */ String meth = "get" Foo."$meth"(1) 有没有办法
在 ECMAScript6 中,您可以使用扩展运算符来解构这样的对象 const {a, ...rest} = obj; 它将 obj 浅拷贝到 rest,不带属性 a。 有没有一种干净的方法可以在
我有几个函数返回数字或None。我希望我的包装函数返回第一个不是 None 的结果。除了下面的方法之外,还有其他方法吗? def func1(): return None def func2(
假设我想设计一个 REST api 来讨论歌曲、专辑和艺术家(实际上我就是这样做的,就像我之前的 1312414 个人一样)。 歌曲资源始终与其所属专辑相关联。相反,专辑资源与其包含的所有歌曲相关联。
这是我认为必须经常出现的问题,但我一直无法找到一个好的解决方案。假设我有一个函数,它可以作为参数传递一个开放资源(如文件或数据库连接对象),或者需要自己创建一个。如果函数需要自己打开文件,最佳实践通常
我是一名优秀的程序员,十分优秀!