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


Groups > comp.lang.python > #109895

Re: passing dictionay as argument

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From David Navarro <davisein@gmail.com>
Newsgroups comp.lang.python
Subject Re: passing dictionay as argument
Date Mon, 13 Jun 2016 13:22:50 +0200
Lines 81
Message-ID <mailman.34.1465817812.2288.python-list@python.org> (permalink)
References <0b6372ce-3f16-431b-9e72-42d5c935df14@googlegroups.com> <CAFYRXy+6=CRJVKP5hSD49FuoLDnSCJxdJWs49CXXtzQ3+2b5Qw@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de B0XL/e/sLYIM3heNm0G4RABQYK9/Cbu79koW0JoLzvcg==
Return-Path <davisein@gmail.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; 'error:': 0.05; 'failing': 0.05; 'line:': 0.07; 'cc:addr:python-list': 0.09; 'authorize': 0.09; 'type:': 0.09; 'typeerror:': 0.09; 'python': 0.10; 'syntax': 0.13; 'argument': 0.15; '2016': 0.16; 'code?': 0.16; 'dictionaries': 0.16; 'dictionary.': 0.16; 'hashable': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'unhashable': 0.16; 'wrote:': 0.16; 'creates': 0.18; 'email addr:gmail.com&gt;': 0.18; 'changes': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'keys': 0.22; 'pass': 0.22; 'cc:no real name:2**0': 0.22; 'elements': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'error': 0.27; 'define': 0.27; 'equivalent': 0.27; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; "skip:' 10": 0.28; 'be:': 0.29; 'dictionary': 0.29; 'follows': 0.29; 'code:': 0.29; 'url:mailman': 0.30; 'work.': 0.30; 'putting': 0.30; 'source': 0.33; 'url:python': 0.33; 'url:listinfo': 0.34; "skip:' 20": 0.34; 'received:google.com': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'beginning': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'skip:4 10': 0.38; 'received:209': 0.38; 'url:mail': 0.40; 'skip:a 40': 0.64
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=GGwI7/bgGqIqFHREifgvIn1XEjYsQl8ZvOo5jvzXjqQ=; b=GYi/6exr1dD04WZgl+nZBtKcedZQyWLe/6Kwo8OfqBoqniZn3mCQVWjJylQkpxdHCf gNHXfRt0Si4xa5suQxsjPM7reAsQd1YyIFmP2DdGawYsktoGStbRoE3N666FVUJeLmY0 BJDTvCKOeDqHoP84B7uGGIkX/tERAyr4fpTi6RxbTHf7bIEqV+FUhZ+KBBsvHFF7K5ux 2z5wsI43KDDJ5+Nf3KRy+s5ccXITImIrdXmtsJeLVjSzZoSZdkoVn9aTT9+0oEGs6RBS xdPu5XL31brn/GSqiJILsYWm7K7llYdaTvvziWjSSO7Y5vDSqnQ3ljPU5TQWW5kNugS/ TFHg==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=GGwI7/bgGqIqFHREifgvIn1XEjYsQl8ZvOo5jvzXjqQ=; b=GIi+Y+G3lo2CPftLYmoQhcbPD9Ilcqi1B5mQWhUq7gPeAV/X3KWcXeW+3/ygubW94T DCzWqquwbv6Xx19lDYz0Qs24I53OFZKRsq/nUWcc8xFsY+v453mV99hPowaJirfVMttt QGRq44SY16bk9wrLz6HtTXQJpuv+S3iPyUjJImX7/uvBPsT0mtkkF0sgoX1MO81ZhT/1 gy1HDYTZsX51LW/7CTcprfwckgwKHTo5EGAFYP2A5N5VxitrdcMXgJAc9IASG2gf+nr5 nYPQoJVnQSaeryEYjhY2fYJHueOqR7ccafBb81nDKeYjX6GDDlhkbQKOiQkUGhg4CAxv ZukA==
X-Gm-Message-State ALyK8tK7W97+hJKccTk/mXv0TBEYDBu36IBlLt4N2kpYGV20twuCn+MXUuaf1vEpb8zuU4e2RL43RwEFyGaC6A==
X-Received by 10.140.109.36 with SMTP id k33mr6798538qgf.80.1465816999979; Mon, 13 Jun 2016 04:23:19 -0700 (PDT)
In-Reply-To <0b6372ce-3f16-431b-9e72-42d5c935df14@googlegroups.com>
X-Mailman-Approved-At Mon, 13 Jun 2016 07:36:51 -0400
X-Content-Filtered-By Mailman/MimeDel 2.1.22
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 <CAFYRXy+6=CRJVKP5hSD49FuoLDnSCJxdJWs49CXXtzQ3+2b5Qw@mail.gmail.com>
X-Mailman-Original-References <0b6372ce-3f16-431b-9e72-42d5c935df14@googlegroups.com>
Xref csiph.com comp.lang.python:109895

Show key headers only | View raw


To be equivalent to the other one it should be:

result = authorize.Transaction.sale({'amount': 40.00, 'credit_card':
credit_card})

In this line:
result = authorize.Transaction.sale({40.00,credit_card})

You are not putting keys in the dictionary. If there are no keys Python
creates a 'set literal'. The error you are seeing is failing to create the
set (sets require all their elements to be hashable and dictionaries
aren't).

If you use the line at the beginning of the mail it should work.

On 13 June 2016 at 12:54, Arshpreet Singh <arsh840@gmail.com> wrote:

> I have to pass dictionary as function argument for following code:
>
> </code>
> import authorize
>
> authorize.Configuration.configure(
>     authorize.Environment.TEST,
>     'api_login_id',
>     'api_transaction_key',
> )
>
> result = authorize.Transaction.sale({
>     'amount': 40.00,
>
>     'credit_card': {
>         'card_number': '4111111111111111',
>         'expiration_date': '04/2014',
>         'card_code': '343',
>     }
>
> })
>
> result.transaction_response.trans_id
>
> </code>
>
> I want to define 'credit-card' dictionary as argument in the function as
> follows but it returns syntax error:
>
> </code>
>
> # define dictionary outside the function call:
> credit_card={
>         'card_number': '4111111111111111',
>         'expiration_date': '04/2014',
>         'card_code': '343',
>     }
>
> import authorize
>
> authorize.Configuration.configure(
>     authorize.Environment.TEST,
>     'api_login_id',
>     'api_transaction_key',
> )
>
> result = authorize.Transaction.sale({'amount': 40.00,credit_card})
>
> result.transaction_response.trans_id
>
> it returns following error:
>
> result = authorize.Transaction.sale({40.00,credit_card})
> TypeError: unhashable type: 'dict'
>
> Do I need to make changes in authorize.Transaction.sale() source code?
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
David Navarro Estruch

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


Thread

passing dictionay as argument Arshpreet Singh <arsh840@gmail.com> - 2016-06-13 03:54 -0700
  Re: passing dictionay as argument David Navarro <davisein@gmail.com> - 2016-06-13 13:22 +0200
  Re: passing dictionay as argument marco.nawijn@colosso.nl - 2016-06-13 04:36 -0700
  Re: passing dictionay as argument "Frank Millman" <frank@chagford.com> - 2016-06-13 13:39 +0200

csiph-web