Solved

Help with some Python code (Noobie)

Posted on 2015-02-05
5
60 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 500 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

749 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