博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python基础 - 文件读写
阅读量:7230 次
发布时间:2019-06-29

本文共 445 字,大约阅读时间需要 1 分钟。

完成功能:

  从指定位置读文件到控制台

#! /usr/bin/python# coding=utf-8方法一、try:        f = open ('/root/python/file/001.txt','r' )        print(f.read())finally:        if f:           f.close()方法二、with open('/root/python/file/001.txt','r') as f:        print (f.read())方法三、f = open ('/root/python/file/001.txt','r' )for line in f.readlines():        print (line.strip())

效果:

[root@localhost python]# ./004_IO-test.py 111111111111111222222222222222333333333333333

 

转载地址:http://eadfm.baihongyu.com/

你可能感兴趣的文章
更好用的集群限流功能,Sentinel 发布 v1.4.2
查看>>
Python(生成执行文件)
查看>>
redis安装配置 - ttlsa教程系列之redis
查看>>
Linux --DHCP服务器配置;DHCP服务器中继
查看>>
IE版本多的可爱_已迁移
查看>>
eclipse查看jar包中class的中文注释乱码问题的解决
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
mariadb安装
查看>>
vue+vuex+axios+echarts画一个动态更新的中国地图
查看>>
5.8 volumetric post-processing--game programming gems5 笔记
查看>>
8086的地址空间
查看>>
Android开发动画效果被遮掉的解决方法
查看>>
Apache2.2.17源码编译安装以及配置虚拟主机
查看>>
2017年开发语言排名
查看>>
读二进制表的显示 Binary Watch
查看>>
我的友情链接
查看>>
linux基础:10、基础命令(4)
查看>>
linux中强大的screen命令
查看>>
放开那个程序员
查看>>