1.FileIO操作文件

# 文件IO,读取文件和创建文件
# 1.读取键盘输入
x=input("please input number")
print("您输入的是"+x) # 2.打开一个文件(open函数相当于创建一个file对象)
fo = open("test.sh", "r+")
print("文件名: ", fo.name)
print("是否已关闭 : ", fo.closed)
print("访问模式 : ", fo.mode)
print("文件位置 : ", fo.tell()) # 3.去读打开的上面的文件进行操作(传负数代表读取所有)
content = fo.read(-1)
print(content) # 4.向文件中写内容
fo.write("llllllllllllll")
fo.flush()
content1 = fo.read(-1)
print(content1)

2.OS模块处理文件和目录

# OS模块处理文件和目录
import os
# 打印当前目录
print(os.getcwd())
# 打印环境变量
print(os.getenv("path"))
# 改变工作目录
path="C:/Users/liqiang/Desktop"
os.chdir(path)
print(os.getcwd()) # 删除目录
os.removedirs("pythonDir")
# 创建目录
os.mkdir("pythonDir")
# 进入当前目录的pythonDir子目录
os.chdir("pythonDir")
print(os.getcwd())
# 创建两个文件
open("test1.txt",'w')
open("test2.txt",'w')
# 列出文件夹下的文件内容
print(os.listdir(os.getcwd()))

最新文章

  1. maven_spring mvc_mina_dome(实体,文件,批传)(spring mina 初学dome)
  2. 转:认识MyBean
  3. 【8-30】oracle数据库学习
  4. 机器学习实战 - 读书笔记(12) - 使用FP-growth算法来高效发现频繁项集
  5. HashTable Dictionary HashMap
  6. 我用的/etc/vimrc
  7. 机器学习公开课笔记(3):Logistic回归
  8. Google地图接口API之Google地图 API 参考手册(七)
  9. sql左连接,右连接,内连接
  10. 《黄聪:手机移动站SEO优化教程》3、如何禁止百度对PC网站进行自动转码
  11. BZOJ2299: [HAOI2011]向量
  12. C#技术------垃圾回收机制(GC)
  13. C# 判断字符串是否可以转化为数字
  14. PHP学习笔记,自己动手写个MVC的框架 -- base所有代码
  15. 在Servlet中使用JSON
  16. jdk 环境变量配置方法总结
  17. ORACLE SEQUENCE的简单介绍
  18. G面经Prepare: Print Zigzag Matrix
  19. SELECT INTO和INSERT INTO SELECT的区别
  20. MySQL事务(学习笔记)

热门文章

  1. centos中apache自用常用额外配置记录(xwamp)
  2. http://www.pythonchallenge.com/ 网站题解
  3. 洛谷 P2900 [USACO08MAR]土地征用Land Acquisition 解题报告
  4. python创建多维列表
  5. iOS之富文本(一)
  6. Codeforces 931.F Teodor is not a liar!
  7. mysql日志配置
  8. windows 安装 apache 服务以及添加 php 解析
  9. web系统中上下移动功能的实现
  10. stout代码分析之零