Python基础——如何使用文件及目录
来源:互联网 发布:淘宝赚佣金的手机软件 编辑:程序博客网 时间:2024/06/05 23:40
#!/usr/bin/python
# * coding: UTF-8 *
open a file
fo = open(‘fo.txt’,’wb’)
print fo.name #return the filename
print fo.closed #return a boolen if the file is closed.return ture
print fo.mode #return the file access mode
print fo.softspace #
write and read file
fo.write(“www.baidu.com “)
fo.write(“www.google.com”)
the file location
fo = open(‘fo.txt’,’r+’)
s1 = fo.read(10)
s2 = fo.read(10)
s3 = fo.read(10)
print s1
print s2
print s3
position = fo.tell()
print ‘now the file position is :’, position
fo.seek(0,0)
print fo.read(10)
print ‘now the file position is :’, fo.tell()
fo.close()
how to operate the file you should use the os moudle
import os #import os module
os.rename(‘fo.txt’,’foo.txt’) #rename file name
try:
foo = open(‘fo.txt’,’r+’)
#use try except to open the file if the file not exist throw the message
except:
print ‘the file not exsit’
remove the file
os.remove(‘fo.txt’)
how to operate the contents
print os.path.abspath(‘.’)
- Python基础——如何使用文件及目录
- 使用Python对操作文件及目录
- python基础之删除文件及删除目录的方法
- python目录及文件操作
- Python 操作文件及目录
- Python 操作文件及目录
- Python 操作文件及目录
- Python基础——如何使用PyInstaller打包python程序
- python基础学习(6)—使用Python处理文件
- Python基础 —— 获取当前文件所在目录,遍历当前目录,获取指定后缀的文件
- python基础——软件目录规范
- Android 文件目录及使用
- Python基础-操作文件和目录
- Python基础-操作文件和目录
- Java基础创建文件及目录
- Linux目录结构及文件基础操作
- Linux 目录及文件基础命令操作
- Python 常用文件及目录操作
- 设计模式系列(四)——装饰模式
- 20.leetcode题目67: Add Binary
- ICE介绍 (RFC 5245)
- DELL R730安装xenserver 6.2,raid卡驱动问题
- 方法重载
- Python基础——如何使用文件及目录
- Zoj 3811并查集
- ZeroC Ice IceBox使用
- BZOJ2190(欧拉函数)
- JZOJ 3101【NOIP2012提高组】开车旅行
- 浅谈百度地图的简单开发之结合方向传感器实现定位功能(三)
- 梧桐树
- Java中Map按值排序
- 反射