Re: passing dictionay as argument
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: > > > 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': '4111', > 'expiration_date': '04/2014', > 'card_code': '343', > } > > }) > > result.transaction_response.trans_id > > > > 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': '4111', > '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}) -- https://mail.python.org/mailman/listinfo/python-list
Re: passing dictionay as argument
"Arshpreet Singh" wrote in message news:0b6372ce-3f16-431b-9e72-42d5c935d...@googlegroups.com... I have to pass dictionary as function argument for following code: [...] result = authorize.Transaction.sale({ 'amount': 40.00, 'credit_card': { 'card_number': '4111', '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': '4111', '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 -- https://mail.python.org/mailman/listinfo/python-list
Re: passing dictionay as argument
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 Singhwrote: > I have to pass dictionary as function argument for following 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': '4111', > 'expiration_date': '04/2014', > 'card_code': '343', > } > > }) > > result.transaction_response.trans_id > > > > 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': '4111', > '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 -- https://mail.python.org/mailman/listinfo/python-list
passing dictionay as argument
I have to pass dictionary as function argument for following 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': '4111', 'expiration_date': '04/2014', 'card_code': '343', } }) result.transaction_response.trans_id 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': '4111', '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