vendredi 29 mai 2015

Python what is wrong with my if statement? (raw_input)

What I want to check for is if the user input is an empty string. I want the code to execute and output: "No input", however whenever I enter no input it goes to the next if statement and executes that with a blank value.

import urllib
import re 
myString = " "
i = 0

def getStockPrice():
    text_file = open("data.txt", "w")
    url = "http://ift.tt/Jz88mB" + symbolslist
    htmlfile = urllib.urlopen(url)
    htmltext = htmlfile.read()

    regex = '<span id="yfs_l84_' + symbolslist+ '">(.+?)</span>'
    pattern = re.compile(regex)

    price = re.findall(pattern,htmltext)
    if str(price) == myString:
        print "No input"
    else:
        print "the price of", symbolslist," is ", price
        text_file.write(str(price))
        text_file.close()




dino = raw_input("What stock would you like to Check?: ")
symbolslist = dino
getStockPrice()

while i < 1000:
    lilly = raw_input("What other stocks do you want to check?: ")
    symbolslist = lilly
    getStockPrice()

Aucun commentaire:

Enregistrer un commentaire