Python 文件打开
【摘要】 在服务器上打开文件假设我们有以下文件,位于与 Python 相同的文件夹中:demofile.txtHello! Welcome to demofile.txtThis file is for testing purposes.Good Luck!如需打开文件,请使用内建的 open() 函数。open() 函数返回文件对象,此对象有一个 read() 方法用于读取文件的内容:实例f = o...
在服务器上打开文件
假设我们有以下文件,位于与 Python 相同的文件夹中:
demofile.txt
Hello! Welcome to demofile.txt
This file is for testing purposes.
Good Luck!
如需打开文件,请使用内建的 open() 函数。
open() 函数返回文件对象,此对象有一个 read() 方法用于读取文件的内容:
实例
f = open("demofile.txt", "r")
print(f.read())
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)