(1)打印到屏幕:print
 (2)读取键盘输入:input/raw_input

 #键盘输入
str = raw_input("Please enter:");
print ("你输入的内容是: ", str) str = input("Please enter:");
print ("你输入的内容是: ", str)

(3)打开文件 open 关闭close 读取read

 #打开与关闭文件
# 打开一个文件
fo = open("foo.txt", "wb")
print ("文件名: ", fo.name)
print ("是否已关闭 : ", fo.closed)
print ("访问模式 : ", fo.mode)#wb
print ("末尾是否强制加空格 : ", fo.softspace)
 # 打开一个文件 不存在就创建
fo = open("foo.txt", "wb")
print ("文件名: ", fo.name)
fo.close() # 打开一个文件
fo = open("foo.txt", "wb")
fo.write( "www.runoob.com!\nVery good site!\n"); # 关闭打开的文件
fo.close() # 打开一个文件
fo = open("foo.txt", "r+")
str = fo.read(10);
print ("读取的字符串是 : ", str)
# 关闭打开的文件
fo.close() # 打开一个文件
fo = open("foo.txt", "r+")
str = fo.read(10);
print ("读取的字符串是 : ", str)

(4)查找位置 定义指针位置

 # 查找当前位置
position = fo.tell();
print ("当前文件位置 : ", position) # 把指针再次重新定位到文件开头
position = fo.seek(0, 0);
str = fo.read(10);
print ("重新读取字符串 : ", str)
# 关闭打开的文件
fo.close()

(5)文件重命名和删除

 import os

 # 重命名文件test1.txt到test2.txt。
os.rename( "test1.txt", "test2.txt" ) import os # 删除一个已经存在的文件test2.txt
os.remove("test2.txt")

最新文章

  1. visual studio 2005 常用按键
  2. request.querystring和request.form、session的区别
  3. Android之startActivityForResult的使用
  4. 十分钟搞懂什么是CGI
  5. gdb 基本命令
  6. algorithm@ find the shortest path in a graph using BFS
  7. JAVA学习:方法
  8. 利用协议代理实现导航控制器UINavigationController视图之间的正向传值和反向传值
  9. Animation 的setFillAfter
  10. ARP欺骗分析
  11. [java] 在linux+chrome/firefox上使用java applet
  12. 推箱子 HDU1254 (bfs)
  13. vue中封装一个全局的弹窗js
  14. 打通WordPress和微信公众号
  15. 【LOJ】#2525. 「HAOI2018」字串覆盖
  16. T-Sql常用语句
  17. window10下Docker安装
  18. 使用Kafka、Elasticsearch、Grafana搭建业务监控系统(三)Elasticsearch
  19. 78W的数据使用forall 进行批量转移;
  20. mysql 实验

热门文章

  1. 【spring boot】mybatis启动报错:Consider defining a bean of type 'com.newhope.interview.dao.UserMapper' in your configuration. 【Mapper类不能被找到】@Mapper 和@MapperScan注解的区别
  2. 大话大前端时代(一) —— Vue 与 iOS 的组件化
  3. MVC Page分页控件
  4. FastDFS的配置、部署与API使用解读(3)以流的方式上传文件的客户端代码(转)
  5. C++函数模板例子
  6. 项目问题总结2:GUID区分大写和小写吗?
  7. 【网站支付PHP篇】thinkPHP集成汇潮支付(ecpss)
  8. Hadoop如何计算map数和reduce数
  9. 6.游戏特别离不开脚本(4)-应该避免将集合框架对象传给JS
  10. DELPHI中的消息处理机制(三种消息处理方法的比较,如何截断消息)