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


Groups > comp.lang.python > #110565

Re: I seem to be creating a dict that I cannot access the keys of

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From dieter <dieter@handshake.de>
Newsgroups comp.lang.python
Subject Re: I seem to be creating a dict that I cannot access the keys of
Date Mon, 27 Jun 2016 09:08:16 +0200
Lines 32
Message-ID <mailman.21.1467011309.2358.python-list@python.org> (permalink)
References <8c9b5b13-c6cc-458d-9d31-56f7e5db10c4@googlegroups.com> <871t3llnao.fsf@handshake.de> <mailman.110.1466841055.11516.python-list@python.org> <fcacd6e0-b0d7-45e4-830a-3de93aab4299@googlegroups.com> <8737nz9kin.fsf@handshake.de>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace news.uni-berlin.de UtkApZbFI1DhVhtGc6a1Rg0T1/hmWnxReljOz1dxENZQ==
Cancel-Lock sha1:3Mmp/FXtCOFRJDUP43T7lUtnirU=
Return-Path <python-python-list@m.gmane.org>
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; 'resulting': 0.04; 'root': 0.04; 'string.': 0.04; '(using': 0.07; '*not*': 0.07; 'exception.': 0.07; 'inserted': 0.09; 'objects.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:keys': 0.09; 'def': 0.13; '(!)': 0.16; 'attributes).': 0.16; 'correctly,': 0.16; 'iterated': 0.16; 'nodes': 0.16; 'read:': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'result:': 0.16; 'subject:access': 0.16; 'surprising': 0.16; 'obviously': 0.16; 'string': 0.17; 'attribute': 0.18; 'tree': 0.18; 'converted': 0.22; 'function,': 0.22; 'code.': 0.23; 'defined': 0.23; 'header :User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:e 30': 0.27; 'str': 0.29; 'subject:that': 0.29; 'comments': 0.30; 'code': 0.30; 'mapping': 0.35; 'should': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'charset :us-ascii': 0.37; 'wrong': 0.38; 'anything': 0.38; 'means': 0.39; 'does': 0.39; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'sample': 0.63; 'here': 0.66; 'composing': 0.84; 'expect.': 0.84; 'successively': 0.84; 'url:tutorial': 0.91
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57b38b79.dip0.t-ipconnect.de
User-Agent Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)
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 <8737nz9kin.fsf@handshake.de>
X-Mailman-Original-References <8c9b5b13-c6cc-458d-9d31-56f7e5db10c4@googlegroups.com> <871t3llnao.fsf@handshake.de> <mailman.110.1466841055.11516.python-list@python.org> <fcacd6e0-b0d7-45e4-830a-3de93aab4299@googlegroups.com>
Xref csiph.com comp.lang.python:110565

Show key headers only | View raw


Sayth Renshaw <flebber.crue@gmail.com> writes:
>> The code below is obviously wrong - it is surprising that you get
>> anything other than an exception. See comments below inserted into
>> your code.
>> 
>> > def parseXML():
>> > ...
>> >             result = etree.tostring(tree.getroot(), pretty_print=True)
>> 
>> "result" here is obviously a string.
>> 
>> >             for sample in result:
>> 
>> This means that "sample" successively hold the characters composing
>> the string "result".
>> 
>> >                 noms = (dict(zip(atts, map(sample.attrib.get, atts))))
>> 
>> You should get "AttributeError: str object does not have attribute `attrib`".
>
> The attrib is an lxml function, when you have defined a root 
> http://lxml.de/tutorial.html

Correctly, this should read: "attrib" is an attribute of "ETree" nodes (!)
(providing a mapping like access to the nodes attributes).

It is *NOT* an attribute of string (!) objects.

You have converted the tree root into a string (using "etree.tostring")
and then iterated over the resulting string. On those characters
you access "attrib" - which will not work as you expect.

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


Thread

I seem to be creating a dict that I cannot access the keys of Sayth Renshaw <flebber.crue@gmail.com> - 2016-06-23 20:59 -0700
  Re: I seem to be creating a dict that I cannot access the keys of dieter <dieter@handshake.de> - 2016-06-25 09:50 +0200
    Re: I seem to be creating a dict that I cannot access the keys of Sayth Renshaw <flebber.crue@gmail.com> - 2016-06-25 01:41 -0700
      Re: I seem to be creating a dict that I cannot access the keys of dieter <dieter@handshake.de> - 2016-06-27 09:08 +0200

csiph-web