Python文件读写+创建临时文件夹的基本方法
来源:互联网 发布:软件开发技术要求 编辑:程序博客网 时间:2024/05/19 13:25
#!/usr/bin/python# -*- coding: UTF-8 -*-import osdef makeTempDir():"""设定缓存目录,为当前文件夹的temp文件夹如果没有对应文件夹则创建文件夹:return: temp_pwd"""temp_pwd = os.path.join(os.getcwd(), 'temp') # 文件缓存目录为当前文件夹下的temp文件夹if os.path.exists(temp_pwd) == False:os.makedirs(temp_pwd)return temp_pwddef test():temp_pwd = makeTempDir()with open(os.path.join(temp_pwd,'test.txt'), 'w') as f: #写文件,没有文件则会创建for i in range(10):f.write("python\n")with open(os.path.join(temp_pwd,'test.txt'), 'r') as f:lines = f.readlines() #一次性读所有的行print linesfor line in lines[5:]: #只处理读出来的后5行line = line.strip('\n')print linedef main():test()if __name__ == '__main__':main()
0 0
- Python文件读写+创建临时文件夹的基本方法
- python中创建临时文件夹
- python 读写、创建 文件的方法(必看)
- Python读写文件的方法
- 查看临时文件夹的方法!
- Delphi 文件读写的基本方法
- [Python]读写文件方法
- python读写文件基本操作
- python 读写文件基本操作方法
- PYTHON读写xml文件的方法
- python中读写csv文件的方法
- python 创建读写目录,文件
- 在C++中实现文件的读写的基本方法
- 在C++中实现文件的读写的基本方法
- python 临时文件夹 的 tempfile模块学习
- python 临时文件夹 的 tempfile模块学习
- Python文件的读写
- python文件的读写
- Android Studio的安装
- 【算法】寻找丢失的数字
- 添加返回导航按钮backBarButtonItem 私人日志
- HUD 6015 Skip the Class
- 【Java】天才第一步——HelloJava
- Python文件读写+创建临时文件夹的基本方法
- OrmLite
- 2017年小米春招内推面试面经
- 回调函数
- 暂时解决unable to access 'https://github.com/Homebrew/brew/': Failed to connect to github.com
- HTTPS小记
- 常用排序算法总结
- 从今天开始在博客记录我在学习过程中的一些问题
- Leetcode 84. Largest Rectangle in Historam