Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFtxe-00016z-Et for pgsql-general@arkaria.postgresql.org; Tue, 08 May 2018 04:10:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fFtxa-0003qO-Kz for pgsql-general@arkaria.postgresql.org; Tue, 08 May 2018 04:10:42 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFtxa-0003q2-9N for pgsql-general@lists.postgresql.org; Tue, 08 May 2018 04:10:42 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFtxS-0000OG-Cv for pgsql-general@lists.postgresql.org; Tue, 08 May 2018 04:10:40 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 45D3122A2B; Tue, 8 May 2018 00:10:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 08 May 2018 00:10:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=qXpadlfybhXKtyo6Q2h9M2TGwBeVJ g92fHUIdfLNFG4=; b=Qyyt1eyO7a8UlEVG5j5q2m++P4Zj9LQgWriijbpwRQM9e eV0Ml1aVaMrFI7KnimRR1d2z6IJN/wyCo6u3YlLGzj4x8C3U20BN2yI3OWFwbkE9 Fo3bsd/tbGwREbv6aY6ybZix7O0ykNXaBCap0yUyQEQqUQWJgQuws/i5cmNKdS3g O7uCJMPjzjUQKz1AxylGZ+NZUTrYGUaTTOW7F3rT91aBLasyVUhUKG6jLJP8vTM7 DkJEIunl4bel4megAM7V4aZKmqj+06HMDitG5PPkL/eUejhn766lBVcOB2gIZtPU 3zPbOfd9Un4ziVE6Pdnt7um46PvQfDLO67HlaABpw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=qXpadl fybhXKtyo6Q2h9M2TGwBeVJg92fHUIdfLNFG4=; b=B7a7hKyI9yffcyoTTNFJ3V 6EbfqSzuY7+9z14JqXI2ZP1CHeVaC9ocj1DAIR1EoUO2QP6Y9VEBhfyDmKvIb5Ru jatlnzrk5nC4aiQkUyjhZNPl2cGdm13gIx7Fd8RFZIc5TwhtSz7kBrWW7W0EHhIh YsMkVaGcMnvt2NZ29txYdsKnvrf1Ptyj8rdbzIP5mIBNt5lBgzo2sm63wJ+xs3HR 86NUheUHv1TCC5aWWyEJ/tBEVMnvXyF03rrjyY0OpQeXNQr/pkO10UJJ9dPVH7iG MzWw11dF2L4Mr4XJ8efhoJd+1T8YIOu68vW92P2WIfAsQYXwmc5N36LW4mgVEXpg == X-ME-Sender: Received: from [192.168.1.2] (unknown [71.212.135.74]) by mail.messagingengine.com (Postfix) with ESMTPA id A5EC21025C; Tue, 8 May 2018 00:10:32 -0400 (EDT) Subject: Re: KeyError: self._index[x] To: tango ward , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: <4fed56f4-052a-8b5b-4b2a-5c108cf2e60e@aklaver.com> Date: Mon, 7 May 2018 21:10:31 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 05/07/2018 08:11 PM, tango ward wrote: > Sorry, accidentally pressed send. > > > cur_p = conn_pr(cursor_factory=psycopg2.extras.DictCursor) > cur_t = conn_t.cursor(cursor_factory=psycopg2.extras.DictCursor) > > > cur_t.execute(""" >                 SELECT TRANSLATE(snumber, ' ', '') >                 FROM sprofile """) > DictCursor is a hybrid dict/sequence. > # This will result in KeyError > for row in cur_t: > print row['snumber'] Above you are using it as a dict and as David pointed you would need to use translate as the key: test=> select translate('test', '', ''); translate ----------- test > > # This works fine > for row in cur_t: > print row[0] Above you are using as a sequence, so the indexing works. > > Sorry again. > > I would really appreciate any suggestions. > > Thanks, > J > -- Adrian Klaver adrian.klaver@aklaver.com