Open Side Menu Go to the Top

06-13-2013 , 01:44 PM
I could write that same method in Python/JS/whatever though and still have it be as clear as the generated documentation from ballin's example.

I totally agree though that there are times when its important to put that information in.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
06-13-2013 , 01:51 PM
Yeah but the description would be missing. "the price of the item" has to go somewhere inside the comments for it to be generated into the docs.

I like Go's take on commenting. It's really light weight comments and their tools generate really insightful docs from it. I mean, they write a lot of comments but it's not pointless stuff, it just explains it in a way that you would expect when reading documentation outside of the source.

Example from their http package:
http://golang.org/src/pkg/net/http/request.go

And the documentation auto generated from those comments:
http://golang.org/pkg/net/http/
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-13-2013 , 02:36 PM
I hate to do this but I'm at an utter loss on this bug.

In English, I essentially am trying to build a stock class to collect some simple stock data. To do this I am parsing the source code of the stock's Yahoo Finance key statistics page.

I created an update function in the stock class that calls my parsing function (pullStockDataField). The problem is this: the type of the parameters inside the parsing function is different than the type of the parameters passed to it in the update function.

I don't know why. If anyone can shed some light onto the situation, it would be greatly appreciated.

Code below. There are print statements in there so if you run it you can see what I'm referring to.

For the record, I'm using Python 2.7.3

Code:
import urllib
import string
import copy

class Stock(object):

    #Maps common stat name to (indexStr, toFindColon)
    dictStatToIndexTuple = {'Price' : ('time_rtq_ticker', False),
                            'Shares Outstanding' : ('>Shares Outstanding', True),
                            'Operating Cash Flow' : ('>Operating Cash Flow (TTM)', True),
                            'Price/Sales' : ('>Price/Sales (ttm)', True),
                            'Price/Earnings (Forward)' : ('>Forward P/E (fye', True),
                            'Price/Book' : ('>Price/Book (mrq)', True),
                            'Enterprise Value/EBITDA' : ('>Enterprise Value/EBITDA (ttm)', True)}

    def __init__(self, name, tag):
        """
        name = a string of the stock's name, to be displayed to user
        tag = a string of the stock's Yahoo! Finance tag
        """
        assert type(name) == str and type(tag) == str
        self.name = name
        self.tag = tag
        self.url = 'http://finance.yahoo.com/q/ks?s=' + tag
        self.statDict = {}
        self.update()

    def update(self):
        """
        Pull and calculate the current stock statistics
        """

        print '=====Types in update function====='

        #Refresh source. Generate error if not connected to internet?
        source = urllib.urlopen(self.url).read() #Need to specify read size to ensure reads all of file?      
        print 'type(source) =', type(source)

        #For each stat pull its value and add it to self.statDict
        for stat in Stock.dictStatToIndexTuple:
            #The paramater used as toFindColon
            print 'type(Stock.dictStatToIndexTuple[stat][1]) =', type(Stock.dictStatToIndexTuple[stat][1]), '\n'
            indexStr = copy.deepcopy(Stock.dictStatToIndexTuple[stat][0])
            toFindColon = copy.deepcopy(Stock.dictStatToIndexTuple[stat][1])
            self.statDict[stat] = self.pullStockDataField(source, indexStr, toFindColon)

    def pullStockDataField(source, indexStr, toFindColon, numOpenTags = 1):
        """
        Given source, a string containing the source code of the
        stock company's Yahoo! Finance Key Statistics page, indexStr,
        a string of characters with which to search the page source for the starting
        index (specifying which data field to pull), and toFindColon, a boolean
        indicating whether or not a displayed colon should be found before displayed
        numbers indicate the value of the data field,
        Returns a float containing the value of the data field.
        """
        
        ##########################
        #Why do the types change?#
        ##########################
        print '=====Types in pullStockDataField function====='
        print 'type(source) =', type(source)
        print 'type(toFindColon) =', type(toFindColon)
        assert type(source) == str and type(indexStr) == str
        assert type(numOpenTags) == int and type(toFindColon) == bool

        #snip...
        
google = Stock('Google', 'GOOG')
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-13-2013 , 02:59 PM
What's your output for that look like?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-13-2013 , 03:06 PM
Code:
>>> 
=====Types in update function=====
type(source) = <type 'str'>
type(Stock.dictStatToIndexTuple[stat][1]) = <type 'bool'> 

=====Types in pullStockDataField function=====
type(source) = <class '__main__.Stock'>
type(toFindColon) = <type 'str'>

Traceback (most recent call last):
  File "C:/Users/Scott Emmons/Desktop/blah.py", line 69, in <module>
    google = Stock('Google', 'GOOG')
  File "C:/Users/Scott Emmons/Desktop/blah.py", line 26, in __init__
    self.update()
  File "C:/Users/Scott Emmons/Desktop/blah.py", line 45, in update
    self.statDict[stat] = self.pullStockDataField(source, indexStr, toFindColon)
  File "C:/Users/Scott Emmons/Desktop/blah.py", line 64, in pullStockDataField
    assert type(source) == str and type(indexStr) == str
AssertionError
>>>
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-13-2013 , 03:09 PM
You're missing a "self" parameter from the look of it

EDIT: yep, looked at the other methods and now I'm positive:

Code:
self.statDict[stat] = self.pullStockDataField(source, indexStr, toFindColon)

    def pullStockDataField(source, indexStr, toFindColon, numOpenTags = 1):
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-13-2013 , 03:17 PM
Ahh, thanks!

That was shifting the position of all the parameters I thought I was passing, then?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-13-2013 , 03:22 PM
Nice catch.

You can see this in your output and how the first parameter is: <class '__main__.Stock'>
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-13-2013 , 03:23 PM
Correct. The only reason the method ran at all was because you thought you had a working default parameter, which was actually taking the value of toFindColon that you meant to pass.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-13-2013 , 03:41 PM
So does the interpreter just pass self as the first argument and the parameters I've passed after that, whether I've remembered to make room for it (self) in the function definition or not?

That would explain what jjshabado was observing that type(source) is: <class '__main__.Stock'>
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-13-2013 , 03:47 PM
Right. There's nothing special about the name "self", it's just a near-universal convention. The first parameter will be self whether you remember it or not.

Usually, if you make this mistake, it tries to pass more parameters than the method can accept and you get a TypeError (that's usually how this error gets noticed). In this case, you had 4 parameters, one of which had a default value, so instead of trying to pass 5 parameters and failing, you passed 4 when you thought you were passing 3.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-13-2013 , 03:59 PM
Thanks, that clears it up!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-13-2013 , 07:22 PM
Quote:
Originally Posted by jjshabado
I once defended one of the TJ Cloutier NL books against someone telling me that it was terrible. I wish I could go back in time and kick my ass.
For the times you can't be blamed... I mean, Little Green Book was about the best literature available for about 2 years (LOL if you thought NL Theory & Practice was good).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-13-2013 , 07:32 PM
This is pretty good:

** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-13-2013 , 10:19 PM
Quote:
Originally Posted by daveT
For the times you can't be blamed... I mean, Little Green Book was about the best literature available for about 2 years (LOL if you thought NL Theory & Practice was good).
I think it was the championship hold'em book. The advice was pretty horrible though. It was an especially bad strategy for taking advantage of all of the horrible NL players that were out there at the time.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-14-2013 , 08:24 AM


I chuckled and changed my default Firefox search bar...because why not
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-14-2013 , 09:09 AM
Switching search engines probably gets you on a watch list. I heard duckduckgo sucks but ixquick.com is better.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-14-2013 , 11:51 AM
DuckDuckGo has been doing a lot of guerrilla marketing, like stickers on light poles, etc. but I dont think the "Google tracks you, we don't" use case is compelling enough to get people to switch long term.

It does also suck pretty hard, imo.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-14-2013 , 11:56 AM
Have you ever gone and looked at your google search history? They have everything you've ever searched for since 2003 or so. It's a little sobering. I doubt there's anyone who wouldn't be at least embarrassed to have that revealed to the world.

It never occurred to me that Google would save our personal search histories w/o asking first, and frankly I'm pretty pissed that they do. You can turn off your web history. But that just means they hide it from you. It doesn't mean they stop saving it.

There was some kind of March 1 deadline this year for shutting it off or something. Naturally I read about that on March 1. So I have no idea if I made the deadline.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-14-2013 , 12:02 PM
it's going to be so embarrassing when people find out about my crush on the Wendy's commercial girl
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-14-2013 , 12:14 PM
When they came for the ginger-lovers, I said nothing...
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-14-2013 , 12:16 PM
Does incognito mode still let them save it?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-14-2013 , 12:21 PM
I think they might match IP or something. From what I read, the only way to be totally safe is to use something like t.0.r. https://www.eff.org/wp/six-tips-prot...search-privacy
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-14-2013 , 12:29 PM
Quote:
Originally Posted by suzzer99
Have you ever gone and looked at your google search history? They have everything you've ever searched for since 2003 or so. It's a little sobering. I doubt there's anyone who wouldn't be at least embarrassed to have that revealed to the world.
I don't understand why it is embarrassing. Who cares what I have searched for?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
06-14-2013 , 12:31 PM
it is well known that larry's only weaknesses are hungry and sleepy
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m