Solved

Help with some Python code (Noobie)

Posted on 2015-02-05
5
55 Views
Last Modified: 2015-02-13
I have some code here that I am looking for some help with

 for e in relevant_data:
        # schedule bids
        delay = e['time_left']
        closing_seconds = int(bot_config['auction_closing_seconds'])
        s.enter(delay.seconds - closing_seconds - 60, 1, pre_login)
        s.enter(delay.seconds - closing_seconds, 1, bid, argument=(e,))
        debug_message += "\n  --  {} {}".format(e['loan_title'],e['time_left'])
    # Testing
    loan_titleNMA = e['loan_title']
    p.push("Loanbot","Available Loans", loan_titleNMA )

Open in new window


Basically , I want to use the value in 'loan_title' as a variable in the p.push (last value)

I tried
    p.push("Loanbot","Available Loans", e['loan_title'] )
and this didn't work so I have been trying various things but I am lost

Can anyone help?
0
Comment
Question by:aideb
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:pepr
Comment Utility
What is the definition of p.push(), and what error do you observe?
0
 
LVL 2

Assisted Solution

by:aideb
aideb earned 0 total points
Comment Utility
p.push is using https://github.com/uskr/pynma

but thats a red herring

Even when i try to pass the current 'loan title' into another variable it doesn't like it
e.g.
loan_titleNMA = e['loan_title']

It throws an exception
0
 
LVL 28

Accepted Solution

by:
pepr earned 500 total points
Comment Utility
You can probably see the KeyError: 'loan_title'. If yes, it means that the 'loan_title' is not in the e dictionary. Or you can test fof the presence of the key like if 'loan_title' in e: ..., or you can use e.get('loan_title', 'default xyz') insted of putting the key to the square brackets. The result is the same. However, if the key is not in the dic, the 'default xyz' is returnet instead (here a string, but can be of any type).
0
 
LVL 2

Author Closing Comment

by:aideb
Comment Utility
I hadn't appreciated that Python was sensitive to the indentation tabs.

As the tab wasn't in line, the for (e) statement was not being executed and therefore when it got to look up  e.'loantitle', it couldn't!
0
 
LVL 28

Expert Comment

by:pepr
Comment Utility
For indentation, consider using spaces only -- 4 spaces for each indentation level. Set your editor to use spaces when pressing tab key.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a…
Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now