readlines(x),总只显示第一行记录
with open(file='C:\\Users\\Administrator\\Desktop\\新建文本文档.txt', mode='r', encoding='GBK' ) as clear:
#result = clear.read(256)
res = clear.readlines(3)
#print(result)
print(res)
终端输出:
['pip install dnspython -i https://pypi.tuna.tsinghua.edu.cn/si #从国内网址下载,速度快\n']
原文本文档:
pip install dnspython -i https://pypi.tuna.tsinghua.edu.cn/si #从国内网址下载,速度快
pip install keras -i http://pypi.douban.com/simple --trusted-host pypi.douban.com #信任网址
python -m pip install --upgrade pip -ihttp://pypi.douban.com/simple --trusted-host pypi.douban.com # 升级pip
pip help 来了解pip支持的命令:
commands:
install:安装 包
download: 下载包
uninstall:卸载包
freeze:按要求格式输出已安装的包
list:列出已安装的包
show:展示已安装包的详细信息
check:验证安装的程序包是否有兼容的依赖项
config:管理本地或全局配置
search:在python包索引中查找包
wheel:根据你的需求构造轮子
hash:
completion:
debug:
help:显示命令列表
正在回答
同学你好:readlines(x)这个函数中的参数是字节的总大小,表示会读取到该文件内对应字节数的当前行。同学你这里写readlines(3)就会读到第3个字节所在的行,即第一行。如果想要全部读出则可以不写这个参数,如下图:

如果解决了你的疑惑,请采纳,祝学习愉快~
- 参与学习 人
- 提交作业 2727 份
- 解答问题 8160 个
想要进入Python Web、爬虫、人工智能等高薪领域,你需要掌握本阶段的Python基础知识,课程安排带你高效学习轻松入门,学完你也能听得懂Python工程师的行业梗。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星