zoukankan      html  css  js  c++  java
  • 按行N等分某个文件


    # --*-- coding:utf-8 --*--
    import random
    import math


    def fanhui():
        into = random.randint(1, 10)
        jiaodu = random.uniform(math.pi/6, math.pi/3)
        # print math.cos(jiaodu)
        if into * math.cos(jiaodu) * 10.0 * math.sqrt(3) < 149:
            return int(math.ceil(into * math.cos(jiaodu) * math.sqrt(3)))
        else:
            fanhui()


    for i in xrange(100):
        # fanhui()
        print fanhui()


    # --*-- coding;utf-8 --*--
    import random
    import time
    import os
    """
    """
    n = 20
    fname = 'test_2505503569_2647000035.txt'

    def getTimeStamp():
        """
        """
        return str(int(time.time() * 1000))

    files = []
    for i in range(1, n + 1):
        name = 'data' + os.sep + str(i) + '_' + getTimeStamp() + '.txt'
        f = open(name, 'w')
        files.append(f)

    f = open(fname, 'r')
    while True:
        line = f.readline()
        if not line:
            break
        line = line.strip()
        idx = random.randint(1, n) - 1
        files[idx].write(line + ' ')

    for file in files:
        file.flush()
        file.close()



    # --*-- coding:utf-8 --*--
    import sys
    fname = sys.argv[1]
    file = open(fname)
    lines = file.readlines()
    print len(lines)
    lines.sort()
    for line in lines:
            print line.strip()
     
  • 相关阅读:
    chrome、firefox、IE中input输入光标位置错位解决方案
    IE兼容opacity
    Linux下redis5的安装及伪分布式集群搭建
    Linux文件编辑命令详细整理
    saltstack
    redis集群
    系统调优
    centos7 telnet 登录升级ssh
    keepalive简单高可用 ha
    docker
  • 原文地址:https://www.cnblogs.com/i80386/p/4167009.html
Copyright © 2011-2022 走看看