python--文件

 2023-09-15 阅读 31 评论 0

摘要:python打开文件权限说明 ========= =====================================&

python打开文件权限说明

========= ===============================================================
    Character Meaning
    --------- ---------------------------------------------------------------
    'r'       open for reading (default)
    'w'       open for writing, truncating the file first
    'x'       create a new file and open it for writing
    'a'       open for writing, appending to the end of the file if it exists
    'b'       binary mode
    't'       text mode (default)
    '+'       open a disk file for updating (reading and writing)
    'U'       universal newline mode (deprecated)
    ========= ===============================================================

python编程,

>>> f = open('d:\\record.txt','w')  #如果不存在创建文件

>>> f = open('d:\\record.txt','r')
>>> type(f)
<class '_io.TextIOWrapper'>

>>>

python怎么运行py文件、#打印每一样数据

>>> lines = list(f)
>>> for each_line in lines:
    print(each_line)
#推荐方式
>>> for each_line in f:
    print(each_line)


python读取csv文件、>>> f = open("d:\\record.txt",'w')
>>> f.write('i love python')
13
>>> f.close()
#关闭文件数据才会冲缓冲区写入文件
>>> f = open("d:\\record.txt",'r')
>>> f.read()
'i love python'


权限模式是open的参数

python ()?>>> f = open('d:\\record.txt','a')
>>> f.write(' i love php too !!')
18
>>> f.close()

>>> f = open('d:\\record.txt','r')
>>> f.read()
'i love python i love php too !!'
>>>



版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/59447.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息