python讀取ini檔案

來源:互聯網
上載者:User

ini:

[COMM]C0 = 0.1C1 = 0.25C2 = 0.35C3 = 0.45C4 = 0.55C5 = 0.56[POS_TAK]PT0 = 0.1PT1 = 1.1PT2 = 2.1PT3 = 3.1PT4 = 4.1PT5 = 5.1[BET_INFO]AMT = 100.23ODDS= 48.5

  py:

#!/usr/bin/env python#coding=gbkimport ConfigParserimport syscomm = []       #commissionpt = []         #position takingamt = 0.0       #bet amtodds = 1.0      #oddsconfig = ConfigParser.ConfigParser()config.read("cfg.ini")#sections = config.sections()#print sections#o = config.options("POS_TAK")#print o#v = config.items("POS_TAK")#print vfor item in config.items("COMM"):    comm.append( float( item[1] ) )for item in config.items("POS_TAK"):    pt.append( float( item[1] ) )amt = float(config.items("BET_INFO")[0][1])odds = float(config.items("BET_INFO")[1][1])print '%10s:%s' % ('comm', comm)print '%10s:%s' % ('pt', pt)print '%10s:%-10.2f' % ('amt', amt)print '%10s:%-10.2f' % ('odd', odds)#################calc#####################c0 = pt[0] * comm[0] * amtc1 = pt[0] * (comm[1] + comm[2] + comm[3] + comm[4] + comm[5]) * amtc2 = (pt[0] + pt[1]) * (comm[2] + comm[3] + comm[4] + comm[5]) * amtc3 = (pt[0] + pt[1] + pt[2]) * (comm[3] + comm[4] + comm[5]) * amtc4 = (pt[0] + pt[1] + pt[2] + pt[3]) * (comm[4] + comm[5]) * amtc5 = (pt[0] + pt[1] + pt[2] + pt[3]+ pt[4]) * (comm[5]) * amt#pn0= pt[0]*amt -c0 -c1          #prize nopn1 = pt[0] * amt - c1pn2 = (pt[0] + pt[1]) * amt - c2pn3 = (pt[0] + pt[1] + pt[2]) * amt - c3pn4 = (pt[0] + pt[1] + pt[2] + pt[3]) * amt - c4pn5 = (pt[0] + pt[1] + pt[2] + pt[3] + pt[4]) * amt - c5#py0= pt[0]*amt -c0 -c1          #prize yespy1 = -(pt[0]) * amt * (odds - 1) - c1py2 = -(pt[0] + pt[1]) * amt * (odds - 1) - c2py3 = -(pt[0] + pt[1] + pt[2]) * amt * (odds - 1) - c3py4 = -(pt[0] + pt[1] + pt[2] + pt[3]) * amt * (odds - 1) - c4py5 = -(pt[0] + pt[1] + pt[2] + pt[3] + pt[4]) * amt * (odds - 1) - c5##############output##########################print '-' * 70print '%10s|%15s %15s %15s' % ('type', 'comm','no prize','prize yes')print '-' * 70print '%10s|%15.2f %15s %15s' % ('lv0', c0,'-','-')print '%10s|%15.2f %15.2f %15.2f' % ('lv1', c1,pn1,py1)print '%10s|%15.2f %15.2f %15.2f' % ('lv2', c2,pn2,py2)print '%10s|%15.2f %15.2f %15.2f' % ('lv3', c3,pn3,py3)print '%10s|%15.2f %15.2f %15.2f' % ('lv4', c4,pn4,py4)print '%10s|%15.2f %15.2f %15.2f' % ('lv5', c5,pn5,py5)print '-' * 70print 'Press ENTER to exit...'sys.stdin.read(1)#if __name__ == '__main__':#    print 'hello  中國'

  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.