?
Solved

Help with some Python code (Noobie)

Posted on 2015-02-05
5
Medium Priority
?
66 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 29

Expert Comment

by:pepr
ID: 40593033
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
ID: 40593104
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 29

Accepted Solution

by:
pepr earned 1000 total points
ID: 40593167
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
ID: 40607542
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 29

Expert Comment

by:pepr
ID: 40609044
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
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…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

840 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