zoukankan      html  css  js  c++  java
  • open read split

    open  来打开文件, 其具体表现为 open('文件名或路径', 'r or w or other', 位置?)

    其生成一个文件类型的对象 file object.

    可写做  

    FILENAME = '文件名或路径'
    #File : file
    File = open(FILE, 'r', 0)

    read 来读取文件的内容,其有三种函数形式,也可扩展更多中。

    有三种函数 分别为  read() readline() readlines()

     http://blog.csdn.net/werm520/article/details/6898473 

    所说,read(),直接读取整个文件,string为其输出。

    /*下面内容瞎猜的*/

    readline()与readlines()将文件分析成一个行的列表,元素为string的list,每个元素为一行string,每行由换行符区分

    /*上面内容瞎猜的*/

    readline()输出为string,readline()一次读一行,

    readlines()输出为元素是string的list,readlines()直接读完整个文件。

    相当于readlines读出的是 一个元素为string的list,其元素就是每个readline()的内容

    readlines[readline,readline,...,readline]

    lines = File.readlines()
    
    while True :
        line = File.readline()
        if line:
            pass
        else:
            break

    可写做

    #line : string
    line = File.readline()

    现在,文件读成了string,若line 中的内容是一长串英文,其每个单词会由空格分隔,那么提取每个单词则可以进行处理

  • 相关阅读:
    大神总结的
    更改Xcode的缺省公司名
    iPhone分辨率
    iOS 的 APP 如何适应 iPhone 5s/6/6Plus 三种屏幕的尺寸?
    storyBoard(tableViewl)
    storyBoard
    XIB可视化编程
    UITableView(五)
    UITableView(四)
    UITableView(三)
  • 原文地址:https://www.cnblogs.com/young-ma/p/4356191.html
Copyright © 2011-2022 走看看