#目录里先创建一个yesterday文件
'''对文件操作流程:
打开文件,得到文件句柄并赋值给一个变量
通过句柄对文件进行操作
关闭文件 '''
print(open('yesterday',encoding='utf-8').read())#utf-8可以换成utf_8
print("\n>>>>>>>>>>>>>>>>>\n>>>>>>>>>>>>>>>>>\n" ) f = open('yesterday',encoding='utf-8') #打开文件(重新打开的,上一步打开过文件)
f = open('yesterday','r',encoding='utf-8')#打开文件,上一步是默认情况下打开读文件,标准是本步骤所写
data=f.read()
data2=f.read()
print(data)#读完之后,光标已在文件最后
print("\n*****************\n*****************\n" )
print(data2)#data2并未被打印出,说明文件只打印了一遍,因为上次读完之后,光标已在文件最后,无法继续读下去
#写文件,即创建新文件
f = open('yesterday2','w',encoding='utf-8')#打开写文件
#注:不能这样f = open('yesterday','w',encoding='utf-8')打开文件,会直接导致yesterday文件变成空文件
f.write("我爱北京天安门,\n")
f.write("这里靠近故宫")
f.close() #关闭文件
#写文件,但是不会覆盖之前的,也不能读出来
f = open('yesterday2','a',encoding='utf-8')#a=apeend 追加
f.write("\n我在天津上学,\n")
f.write("这里有红桥区,北辰区")
data3=f.read()#还是读不出来
print("data3没有被打印出来",data3)
#data = f.read() 读取剩下的所有内容,文件大时不要用读取剩下的所有内容,文件大时不要用

  

我的文件,保存到目录中
1 YESTERDAY ONCE MORE
2 When I was young I'd listen to the radio 当年少时,我爱听收音机
3 Waiting for my favorite songs 等待我最喜爱的歌
4 When they played I'd sing along, 当播放后,我喜欢一个人唱
5 It make me smile 这让我开心的笑了
6 Those were such happy times 像这样快乐的日子
7 and not so long ago 没有多久
8 How I wondered where they'd gone. 我想知道他们去了哪里
9 But they're back again 但他们再次回来
10 just like a long lost friend 像失去很久的朋友
11 All the songs I love so well 所有的歌,我是这么的喜欢
12 Every shalala shalala
13 every wo'wo wo'wo
14 still shines. 依然闪亮
15 Every shing-a-ling-a-ling shing-a-ling-a-ling
that they're starting to sing so fine 他们开始唱歌,是这么美好
When they get to the part 当他们分手
where he's breaking her heart 当他让她伤心
It can really make me cry 这些都让我哭了
just like before. 就像从前一样
It's yesterday once more. 昨日重现
Looking back on 回首看
how it was in years gone by 许多年过去了
And the good times that had 这些好的时光
makes today seem rather sad, 让今天更加难过
So much has changed. 变了这么多
It was songs of love 爱之歌
that I would sing to them 我必须唱给他们听
And I'd memorise each word. 我得记得每个字
Those old melodies 这些古老的旋律
still sound so good to me 我仍然认为非常好听
As they melt the years away 如消失的许多年前一样
Every shalala shalala
every wo'wo wo'wo
still shines. 依然闪亮
Every shing-a-ling-a-ling shing-a-ling-a-ling
that they're starting to sing so fine 他们开始唱歌,是这么美好
All my best memorise come back clearly to me 我的所有美好记忆是这么清晰
Some can even make me cry 一些让我哭泣
just like before. 就像以前一样
It's yesterday once more. 昨日重现
												

最新文章

  1. SSH框架使用注解简化代码
  2. 基于netty轻量的高性能分布式RPC服务框架forest<上篇>
  3. 6款程序员不得不爱的bootstrap模板
  4. 常见绘图框架-(Charts)
  5. 10本Java经典书目推荐
  6. iOS7总显示状态栏的解决方法
  7. linux用户及组管理
  8. popViewControllerAnimated 后,对页面内UITableView 内数据刷新
  9. 总结&记录
  10. 跳转界面方法 (runtime实用篇一)
  11. Django 数据库查询
  12. 深入了解Json转变为map的思想,附源代码2
  13. 通过CSS实现各种方向的三角形
  14. 10_27_unittest
  15. RabbitMQ 分发到多Consumer(Publish/Subscribe)
  16. Hadoop HDFS常用操作命令
  17. gitlab分支代码本地拉取及jenkins关联gitlab分支
  18. Linux - 文件操作
  19. Laravel Blade 模板 @section/endsection 与 @section/show, @yield 的区别
  20. Codeforces Round #319 (Div. 2) E - Points on Plane

热门文章

  1. 【转至hejinde的专栏】Axure RP 8最新激活码(可用注册码)
  2. 洛谷P1171 售货员的难题
  3. DMZ的原理与应用
  4. JAVA之反射(一)
  5. C# AD 验证登陆
  6. js 监听浏览器刷新还是关闭事件
  7. 07.Spring Bean 加载 - BeanDefinitionReader
  8. 014 Longest Common Prefix 查找字符串数组中最长的公共前缀字符串
  9. Sorted Subsegments
  10. mac-httpd