0

I would first like to apologize for how much of a beginner I am, however I have hit this wall after many other hurdles. The basis of this is to retrieve a value from a website, modify it using variables and print the final value. My knowledge of classes and objects is very very minimal. I just cannot figure out how I can take the value numTotal from my function getPlays and use it later to print as Final. The value prints correctly from within the function I just need to store that value for later use as a variable.

class GetPlaycount(object):

    def getPlays(self):
        print "Working"
        browser = webdriver.PhantomJS('C:\Python27\phantomjs-2.0.0-windows\phantomjs.exe')
        browser.get('https://osu.ppy.sh/u/4973241')
        time.sleep(1)
        Plays = browser.find_element_by_xpath('//*[@id="general"]/div[8]').text 
        numPlays = int(re.sub('[^0-9]', '', Plays))
        numTime = int(numPlays) * int(numLength)
        numTotal = int(numTime) * float(numVar)
        print int(numTotal)
        return numTotal


myClassObject = GetPlaycount()

myClassObject.getPlays()

Final = ????

print Final

raw_input("wait")

Thank you for your help and patience.

1 Answer 1

1

If I understand the question correctly

final = myClassObject.getPlays()
print final 

Should be all you need.

Sign up to request clarification or add additional context in comments.

4 Comments

Just tried that, it does print what I need but it runs the function again rather than taking the original value? prntscr.com/7qwbq5
@JesseAshmore, you are already printing in your getPlays() method, that's why you see it printing twice.
@KhalilAmmour-خليلعمور I understand, but it is actually taking the time to run the whole thing again, hence the "Working" twice. It runs it, prints the value, then runs it again and prints again. Can I not run it once, save the output, and print the output rather than running for the output each time. It is now taking twice as long for the program to finish.
That's because you are calling it twice ..@JesseAshmore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.