[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Help with some Python code (Noobie)

Posted on 2015-02-05
5
Medium Priority
?
64 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
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 modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

656 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