?
Solved

Help with some Python code (Noobie)

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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…

752 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