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


Groups > comp.lang.python > #109895

Re: passing dictionay as argument

From David Navarro <davisein@gmail.com>
Newsgroups comp.lang.python
Subject Re: passing dictionay as argument
Date 2016-06-13 13:22 +0200
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>

Show all headers | 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