.. link: http://dgplug.org/summertraining/2013/posts/supriyasaha-sharevalue2-20130712-143231.html .. description: .. tags: .. date: 2013/07/12 14:32:32 .. title: supriyasaha sharevalue2 20130712-143231 .. slug: supriyasaha-sharevalue2-20130712-143231 CODE TO THE PROGRAM ---------------------- the program is based on printing the current shrevalue of the nsdaq .. code:: python #!/usr/bin/env python import urllib2 import sys def get_value(nasdaq): #to get the share value of nasdaq this function will get the share value of nasdaq url='http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=l1' % (nasdaq) #this the url of the nasdaq syambol extracted from yahho.finance con=urllib2.urlopen(url) #to open the url val=con.read() #to read the current share value of nasdaq symbol from yahoo.finanace print "the current sharevalue is %s" % (val) if __name__ == '__main__': #it calls the function to get the current sharevalu if len(sys.argv) == 2: #condition to check whter the file name in the command line does not exceed two it will check for the number of arguments in command line with ./shareval.py get_value(sys.argv[1]) #passe the nasdaq to the main user else: print "Give only one NASDAQ symbol at a time after command line argument!" sys.exit(0) The explanation o the code --------------------------- Here we use import urllib2 to get the current share value of symbol NASDAQ by using a function get_val.Now we open the url lin and read it to get the current sharevalue and print it. '_main_' is used to check weather in the command line input only one input symbol is given or more than one.If it exceed two includin the ./shareval.py then it will exit else it will print the current sharevalue of the symbol the link to the code is https://github.com/supriyasaha/hometaskrepo/blob/master/sharevalue/shareval.py