贴出来一串代码大家看看

为什么80%的码农都做不了架构师?>>>   hot3.png

#!usr/bin/python
#encoding:utf8
#author:cosme
from time import ctime
from urllib import urlopen
import re

ticks = ('YHOO','GOOG','EBAY','AMZN')
URL = 'http://quote.yahoo.com/d/quotes.csv?s=%s&f=slcp2'

print '\nPrices quoted as of: ',ctime()
print '\nTICKER'.ljust(9),'PRICE'.ljust(8),'CHG'.ljust(5),'%AGE'
print '------'.ljust(8),'-----'.ljust(8),'-----'.ljust(5),'-----'

u = urlopen(URL %','.join(ticks))

for row in u:
    tick, price, chg, per = row.split(',')
    mo = re.compile(r'.*>(?P\d+\.\d+)<*').match(price).group('price')
    print eval(tick).ljust(7), mo.rjust(6),chg.rjust(6),eval(per).rjust(6)
不知道不使用正则可以实现不。。。

转载于:https://my.oschina.net/pliot/blog/142205

你可能感兴趣的:(贴出来一串代码大家看看)