• python 文件


    输入

    1.

    fname='in.txt'
    fr=file(fname,'r')
    while k>0:
        line=fr.readline()
        if len(line)==0:
            break
    fr.close()

    2.

    url="in.txt"
    f = open(url,"rb").read()  #这个不用关闭
    words = wtl32(f)

     3.

        fr=open('my_test.out','r')
        line=fr.readline()
        fr.close()

    4. 输入并按单词分句

    def readfile(fname='in.txt'):
        fr=file(fname,'r')
        lines=[]
        while True:
            line=fr.readline()
            if len(line)==0:
                break
            one_line=re.findall(r'[0-9]+',line)
            lines.append(one_line)
        fr.close()
        return lines #//返回以单词为单位的二维数组

     5.

    file_path = 'xx.dat'
    with open(file_path, 'rb') as f:
        for line in f:
            line=line.decode()
            words=line.split('::')

    输出

    1.

    out_f = open("out.txt","wb")
    for j in y:
            print >>out_f,j[0],j[1]# 输出到文件out_f
    out_f.close()

     ============================

    获取当前路径下的所有文件

    import os
    filenames=os.listdir(os.getcwd())
    for name in filenames:
        print name
  • 相关阅读:
    c++的引用 安静点
    mac 安装
    百度小程序canvas
    贝塞尔曲线
    事件循环
    js 模块化
    babel
    rollup babel
    js webgl
    js 异步
  • 原文地址:https://www.cnblogs.com/phoenix13suns/p/2817835.html
Copyright © 2020-2023  润新知