zoukankan      html  css  js  c++  java
  • python读取ini文件

    ini:

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

      py:

    #!/usr/bin/env python
    #coding=gbk
    import ConfigParser
    import sys
    comm = []       #commission
    pt = []         #position taking
    amt = 0.0       #bet amt
    odds = 1.0      #odds
    config = ConfigParser.ConfigParser()
    config.read("cfg.ini")
    
    #sections = config.sections()
    #print sections
    #o = config.options("POS_TAK")
    #print o
    #v = config.items("POS_TAK")
    #print v
    
    for 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] * amt
    c1 = pt[0] * (comm[1] + comm[2] + comm[3] + comm[4] + comm[5]) * amt
    c2 = (pt[0] + pt[1]) * (comm[2] + comm[3] + comm[4] + comm[5]) * amt
    c3 = (pt[0] + pt[1] + pt[2]) * (comm[3] + comm[4] + comm[5]) * amt
    c4 = (pt[0] + pt[1] + pt[2] + pt[3]) * (comm[4] + comm[5]) * amt
    c5 = (pt[0] + pt[1] + pt[2] + pt[3]+ pt[4]) * (comm[5]) * amt
    
    #pn0= pt[0]*amt -c0 -c1          #prize no
    pn1 = pt[0] * amt - c1
    pn2 = (pt[0] + pt[1]) * amt - c2
    pn3 = (pt[0] + pt[1] + pt[2]) * amt - c3
    pn4 = (pt[0] + pt[1] + pt[2] + pt[3]) * amt - c4
    pn5 = (pt[0] + pt[1] + pt[2] + pt[3] + pt[4]) * amt - c5
    
    #py0= pt[0]*amt -c0 -c1          #prize yes
    py1 = -(pt[0]) * amt * (odds - 1) - c1
    py2 = -(pt[0] + pt[1]) * amt * (odds - 1) - c2
    py3 = -(pt[0] + pt[1] + pt[2]) * amt * (odds - 1) - c3
    py4 = -(pt[0] + pt[1] + pt[2] + pt[3]) * amt * (odds - 1) - c4
    py5 = -(pt[0] + pt[1] + pt[2] + pt[3] + pt[4]) * amt * (odds - 1) - c5
    
    ##############output##########################
    print '-' * 70
    print '%10s|%15s %15s %15s' % ('type', 'comm','no prize','prize yes')
    print '-' * 70
    print '%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 '-' * 70
    
    print 'Press ENTER to exit...'
    sys.stdin.read(1)
    #if __name__ == '__main__':
    #    print 'hello  中国'
    

      

  • 相关阅读:
    oracle_jdbc_insert_into
    MySQL 性能比较测试:MySQL 5.6 GA -vs- MySQL 5.5
    centos去下载mysql应该怎么选择linux版本
    centos_radhat升级系统
    phpmyadmin 配置方法
    js 判断js函数,变量是否存在
    mysqlbinlog- 处理二进制日志文件的实用工具 学习笔记
    linux基本命令
    4 MySQL程序概述(包含mysql配置文件配置原理)-学习笔记
    Python学习笔记4 高级特性_20170618
  • 原文地址:https://www.cnblogs.com/wucg/p/2185068.html
Copyright © 2011-2022 走看看