Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109894 > unrolled thread
| Started by | Arshpreet Singh <arsh840@gmail.com> |
|---|---|
| First post | 2016-06-13 03:54 -0700 |
| Last post | 2016-06-13 13:39 +0200 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.python
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
| From | Arshpreet Singh <arsh840@gmail.com> |
|---|---|
| Date | 2016-06-13 03:54 -0700 |
| Subject | passing dictionay as argument |
| Message-ID | <0b6372ce-3f16-431b-9e72-42d5c935df14@googlegroups.com> |
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?
[toc] | [next] | [standalone]
| From | David Navarro <davisein@gmail.com> |
|---|---|
| Date | 2016-06-13 13:22 +0200 |
| Message-ID | <mailman.34.1465817812.2288.python-list@python.org> |
| In reply to | #109894 |
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
[toc] | [prev] | [next] | [standalone]
| From | marco.nawijn@colosso.nl |
|---|---|
| Date | 2016-06-13 04:36 -0700 |
| Message-ID | <a478b2fd-016a-4a01-bc1f-baccdf5f5ea1@googlegroups.com> |
| In reply to | #109894 |
On Monday, June 13, 2016 at 12:54:45 PM UTC+2, Arshpreet Singh 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?
You explicitly need to specify the key for credit_card in the
call to sale(..). I have not run the code myself, but I believe it
will work like this:
result = authorize.Transaction.sale({'amount': 40.00,'credit_card': credit_card})
[toc] | [prev] | [next] | [standalone]
| From | "Frank Millman" <frank@chagford.com> |
|---|---|
| Date | 2016-06-13 13:39 +0200 |
| Message-ID | <mailman.35.1465818002.2288.python-list@python.org> |
| In reply to | #109894 |
"Arshpreet Singh" wrote in message
news:0b6372ce-3f16-431b-9e72-42d5c935df14@googlegroups.com...
> I have to pass dictionary as function argument for following code:
[...]
> result = authorize.Transaction.sale({
> 'amount': 40.00,
>
> 'credit_card': {
> 'card_number': '4111111111111111',
> 'expiration_date': '04/2014',
> 'card_code': '343',
> }
>
[...]
> I want to define 'credit-card' dictionary as argument in the function as
> follows but it returns syntax error:
>
> # define dictionary outside the function call:
> credit_card={
> 'card_number': '4111111111111111',
> 'expiration_date': '04/2014',
> 'card_code': '343',
> }
>
[...]
> result = authorize.Transaction.sale({'amount': 40.00,credit_card})
Try this -
result = authorize.Transaction.sale({'amount': 40.00,
'credit_card':credit_card})
Frank Millman
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web