Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79396 > unrolled thread

No Error; No Output...Nothing

Started byryguy7272 <ryanshuell@gmail.com>
First post2014-10-21 14:44 -0700
Last post2014-10-21 23:41 +0100
Articles 6 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  No Error; No Output...Nothing ryguy7272 <ryanshuell@gmail.com> - 2014-10-21 14:44 -0700
    Re: No Error; No Output...Nothing Chris Angelico <rosuav@gmail.com> - 2014-10-22 08:49 +1100
    Re: No Error; No Output...Nothing Chris Kaynor <ckaynor@zindagigames.com> - 2014-10-21 14:49 -0700
    Re: No Error; No Output...Nothing Matthew Ruffalo <mmr15@case.edu> - 2014-10-21 17:58 -0400
    Re: No Error; No Output...Nothing ryguy7272 <ryanshuell@gmail.com> - 2014-10-21 15:15 -0700
      Re: No Error; No Output...Nothing Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-21 23:41 +0100

#79396 — No Error; No Output...Nothing

Fromryguy7272 <ryanshuell@gmail.com>
Date2014-10-21 14:44 -0700
SubjectNo Error; No Output...Nothing
Message-ID<d84ad0d4-a742-4ca7-93a6-b21f0ed076dd@googlegroups.com>
Hey everyone, I'm trying to run this code.

import os
import pickle
#import urllib2
from urllib.request import urlopen
#import cookielib
import http.cookiejar
import re
import time
import numpy as np
#import pylab as pl
 
# symbol - USDEUR=X - problem that the server sometimes returns 0.0
def getSpotPrice(symbol):
    numberOfAttempts = 0
    while numberOfAttempts < 10:
        url = 'http://download.finance.yahoo.com/d/quotes.csv?s='+symbol+'&f=l1&e=.cs'
        fxrate_pure = urllib2.urlopen(url).read()
        fxrate = fxrate_pure.strip()
        if fxrate != "0.00":
            return fxrate
        else:
            numberOfAttempts += 1
            time.sleep(1)
    raise Exception("Unable to obtain market data from Yahoo! ... wrong ticker???")
 
# symbol = the yahoo ticker; the expected tickers of the components contain alphanumerical characters or dot or hyphen; if the yahoo format changes, nothing is returned
def getConstituentsOfAnIndexFromYahoo(symbol):
    url = 'http://finance.yahoo.com/q/cp?s=%s' % symbol
    p = re.compile('<td class=\"yfnc_tabledata1\"><b><a href=\"/q\?s=([A-Z0-9\.\-]*)\">')
    components = []
    pageIndex = 0
    finished = False
    while not finished:
        if pageIndex == 0:
            actualUrl = url
        else:
            actualUrl = url + "&c=" + str(pageIndex)
        pageResults = p.findall(urllib2.urlopen(actualUrl).read())
        if len(pageResults) == 0:
            finished = True
        else:
            components.extend(pageResults)
            pageIndex+=1
    return components
 
# prices = data[:,6] or prices = data[:, title.index("Adj Close")], pl.num2date(data[:,1]) back dates
# syntax http://ichart.yahoo.com/table.csv?s={Yahoo.Symbol.[isin]}&a={Von.M-1}&b={Von.T}&c={Von.J}&d={Bis.M}&e={Bis.T}&f={Bis. J}&g=d&y=0&z=jdsu&ignore=.csv
def getNumpyHistoricalTimeseries(symbol,fromDate, toDate):
    f = urllib2.urlopen('http://ichart.yahoo.com/table.csv?a='+ str(fromDate.month -1) +'&c='+ str(fromDate.year) +'&b=' + str(fromDate.day) + '&e='+  str(toDate.day) + '&d='+ str(toDate.month-1) +'&g=d&f=' + str(toDate.year) + '&s=' + symbol + '&ignore=.csv')
    header = f.readline().strip().split(",")
    #return np.loadtxt(f, dtype=np.float, delimiter=",", converters={0: pl.datestr2num})

I commented out the import pylab as pl because I couldn't get the matplotlib.pylab import working.  So, anyway, I hit F5, and it seems to run, but it doesn't really do anything.  Isn't this either supposed to be downloading data from the web, or throwing an error so I can troubleshoot, and try to figure out what's going on?  It's hard to troubleshoot, when you don't get any error.  Does this work for others?

Thanks.

[toc] | [next] | [standalone]


#79397

FromChris Angelico <rosuav@gmail.com>
Date2014-10-22 08:49 +1100
Message-ID<mailman.15044.1413928164.18130.python-list@python.org>
In reply to#79396
On Wed, Oct 22, 2014 at 8:44 AM, ryguy7272 <ryanshuell@gmail.com> wrote:
> So, anyway, I hit F5, and it seems to run, but it doesn't really do anything.

It defines a few functions, but nothing ever calls them, so you won't
see much out of it :) Try adding some code at the bottom that actually
calls one of your functions, providing constants for whatever
parameters it needs.

ChrisA

[toc] | [prev] | [next] | [standalone]


#79398

FromChris Kaynor <ckaynor@zindagigames.com>
Date2014-10-21 14:49 -0700
Message-ID<mailman.15045.1413928198.18130.python-list@python.org>
In reply to#79396

[Multipart message — attachments visible in raw view] — view raw

On Tue, Oct 21, 2014 at 2:44 PM, ryguy7272 <ryanshuell@gmail.com> wrote:

> I commented out the import pylab as pl because I couldn't get the
> matplotlib.pylab import working.  So, anyway, I hit F5, and it seems to
> run, but it doesn't really do anything.  Isn't this either supposed to be
> downloading data from the web, or throwing an error so I can troubleshoot,
> and try to figure out what's going on?  It's hard to troubleshoot, when you
> don't get any error.  Does this work for others?


No where in the code are any of the functions being called, so unless your
"F5" is bound to something that will call some functions, I would not
expect it to do anything.

Chris

[toc] | [prev] | [next] | [standalone]


#79400

FromMatthew Ruffalo <mmr15@case.edu>
Date2014-10-21 17:58 -0400
Message-ID<mailman.15047.1413929083.18130.python-list@python.org>
In reply to#79396
On 10/21/2014 05:44 PM, ryguy7272 wrote:
> Hey everyone, I'm trying to run this code.
>
> ...
>
> I commented out the import pylab as pl because I couldn't get the matplotlib.pylab import working.  So, anyway, I hit F5, and it seems to run, but it doesn't really do anything.  Isn't this either supposed to be downloading data from the web, or throwing an error so I can troubleshoot, and try to figure out what's going on?  It's hard to troubleshoot, when you don't get any error.  Does this work for others?
>
> Thanks.
No, it isn't supposed to be downloading data from the web. You have
defined a few functions but you're not actually calling any of them. The
script terminates successfully with no output, since there's nothing for
it to do after executing your imports and function definitions.

Additionally, your attempted use of 'urllib2' inside
getConstituentsOfAnIndexFromYahoo will fail. Your import of that module
is commented out, since (from your imports) you're presumably using
Python 3 and a module with that name no longer exists. Since you have
'from urllib.request import urlopen', you can use the 'urlopen' module
without any fully-qualified name. The relevant line in your
getConstituentsOfAnIndexFromYahoo function should be 'pageResults =
p.findall(urlopen(...'.

MMR...

[toc] | [prev] | [next] | [standalone]


#79401

Fromryguy7272 <ryanshuell@gmail.com>
Date2014-10-21 15:15 -0700
Message-ID<a017c2f3-a279-4b53-929f-325de1e5dffc@googlegroups.com>
In reply to#79396
On Tuesday, October 21, 2014 5:44:33 PM UTC-4, ryguy7272 wrote:
> Hey everyone, I'm trying to run this code.
> 
> 
> 
> import os
> 
> import pickle
> 
> #import urllib2
> 
> from urllib.request import urlopen
> 
> #import cookielib
> 
> import http.cookiejar
> 
> import re
> 
> import time
> 
> import numpy as np
> 
> #import pylab as pl
> 
>  
> 
> # symbol - USDEUR=X - problem that the server sometimes returns 0.0
> 
> def getSpotPrice(symbol):
> 
>     numberOfAttempts = 0
> 
>     while numberOfAttempts < 10:
> 
>         url = 'http://download.finance.yahoo.com/d/quotes.csv?s='+symbol+'&f=l1&e=.cs'
> 
>         fxrate_pure = urllib2.urlopen(url).read()
> 
>         fxrate = fxrate_pure.strip()
> 
>         if fxrate != "0.00":
> 
>             return fxrate
> 
>         else:
> 
>             numberOfAttempts += 1
> 
>             time.sleep(1)
> 
>     raise Exception("Unable to obtain market data from Yahoo! ... wrong ticker???")
> 
>  
> 
> # symbol = the yahoo ticker; the expected tickers of the components contain alphanumerical characters or dot or hyphen; if the yahoo format changes, nothing is returned
> 
> def getConstituentsOfAnIndexFromYahoo(symbol):
> 
>     url = 'http://finance.yahoo.com/q/cp?s=%s' % symbol
> 
>     p = re.compile('<td class=\"yfnc_tabledata1\"><b><a href=\"/q\?s=([A-Z0-9\.\-]*)\">')
> 
>     components = []
> 
>     pageIndex = 0
> 
>     finished = False
> 
>     while not finished:
> 
>         if pageIndex == 0:
> 
>             actualUrl = url
> 
>         else:
> 
>             actualUrl = url + "&c=" + str(pageIndex)
> 
>         pageResults = p.findall(urllib2.urlopen(actualUrl).read())
> 
>         if len(pageResults) == 0:
> 
>             finished = True
> 
>         else:
> 
>             components.extend(pageResults)
> 
>             pageIndex+=1
> 
>     return components
> 
>  
> 
> # prices = data[:,6] or prices = data[:, title.index("Adj Close")], pl.num2date(data[:,1]) back dates
> 
> # syntax http://ichart.yahoo.com/table.csv?s={Yahoo.Symbol.[isin]}&a={Von.M-1}&b={Von.T}&c={Von.J}&d={Bis.M}&e={Bis.T}&f={Bis. J}&g=d&y=0&z=jdsu&ignore=.csv
> 
> def getNumpyHistoricalTimeseries(symbol,fromDate, toDate):
> 
>     f = urllib2.urlopen('http://ichart.yahoo.com/table.csv?a='+ str(fromDate.month -1) +'&c='+ str(fromDate.year) +'&b=' + str(fromDate.day) + '&e='+  str(toDate.day) + '&d='+ str(toDate.month-1) +'&g=d&f=' + str(toDate.year) + '&s=' + symbol + '&ignore=.csv')
> 
>     header = f.readline().strip().split(",")
> 
>     #return np.loadtxt(f, dtype=np.float, delimiter=",", converters={0: pl.datestr2num})
> 
> 
> 
> I commented out the import pylab as pl because I couldn't get the matplotlib.pylab import working.  So, anyway, I hit F5, and it seems to run, but it doesn't really do anything.  Isn't this either supposed to be downloading data from the web, or throwing an error so I can troubleshoot, and try to figure out what's going on?  It's hard to troubleshoot, when you don't get any error.  Does this work for others?
> 
> 
> 
> Thanks.



OK.  Thanks everyone!

[toc] | [prev] | [next] | [standalone]


#79402

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-10-21 23:41 +0100
Message-ID<mailman.15048.1413931281.18130.python-list@python.org>
In reply to#79401
On 21/10/2014 23:15, ryguy7272 wrote:
>
> OK.  Thanks everyone!
>

I'm pleased to see that you have answers.  In return would you please 
access this list via 
https://mail.python.org/mailman/listinfo/python-list or read and action 
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us 
seeing double line spacing and single line paragraphs, thanks.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web