Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6684259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:55:10+00:00 2026-05-26T04:55:10+00:00

Starting with this from Corey Goldberg: #!/usr/bin/env python import json import pprint import urllib2

  • 0

Starting with this from Corey Goldberg:

#!/usr/bin/env python

import json
import pprint
import urllib2


def get_stock_quote(ticker_symbol):   
    url = 'http://finance.google.com/finance/info?q=%s' % ticker_symbol
    lines = urllib2.urlopen(url).read().splitlines()
    return json.loads(''.join([x for x in lines if x not in ('// [', ']')]))


if __name__ == '__main__':
    quote = get_stock_quote('IBM')
    print 'ticker: %s' % quote['t']
    print 'current price: %s' % quote['l_cur']
    print 'last trade: %s' % quote['lt']
    print 'full quote:'
    pprint.pprint(quote)

Using this:

import urllib2, json

def get_stock_quote(ticker_symbol):   
    url = 'http://finance.google.com/finance/info?q=%s' % ticker_symbol
    lines = urllib2.urlopen(url).read().splitlines()
    #print lines
    return json.loads(''.join([x for x in lines if x not in ('// [', ']')]))



if __name__ == '__main__':
    symbols = ('Goog',) 
    symbols2 = ('Goog','MSFT')
    quote = get_stock_quote(symbols)
    print 'ticker: %s' % quote['t'],  'current price: %s' % quote['l_cur'], 'last trade: %s' % quote['ltt']
    print quote['t'],  quote['l'], quote['ltt']

Usings symbols works, symbols2 does not work. The error message is

TypeError: not all arguments converted during string formatting

How do I convert all arguments to string in string formatting. In browser, the code that works is: Goog,MSFT.

EDIT: the output I am looking for is a list with goog, msft info.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:55:11+00:00Added an answer on May 26, 2026 at 4:55 am

    In this case you can make:

    import urllib2, json
    
    def get_stock_quote(ticker_symbol):
        if isinstance(ticker_symbol, (list, tuple)):
            ticker_symbol = ','.join(ticker_symbol)
        url = 'http://finance.google.com/finance/info?q=%s' % ticker_symbol
        lines = urllib2.urlopen(url).read().splitlines()
        #print lines
        return json.loads('[%s]' % ''.join([x for x in lines if x not in ('// [', ']')]))
    
    if __name__ == '__main__':
        symbols = ('Goog',) 
        symbols2 = ('Goog','MSFT')
        quotes = get_stock_quote(symbols2)
        for quote in quotes:
            print 'ticker: %s' % quote['t'],  'current price: %s' % quote['l_cur'], 'last trade: %s' % quote['ltt']
            print quote['t'],  quote['l'], quote['ltt']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been learning python for some time now. While starting this learning python
I am starting this question to try and make a central point developers can
Please note that this is not homework and i did search before starting this
Soooo, I am starting this new job soon where most of the code is
This is starting to vex me. I recently decided to clear out my FTP,
Okay, this is starting to drive me a little bit nuts. I've tried several
Note: This was posted when I was starting out C#. With 2014 knowledge, I
Starting with 2005, VS started this behavior of when starting debugging session it spawns
Starting with the error: Error 81 The OutputPath property is not set for this
Im just starting a project and since this project is personal I was wondering

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.