python 3.x 写 shell sed 替换功能
shell sed 替换功能
f1 = open('yesterday','r',encoding='utf-8')
f2 = open('yesterday2','w',encoding='utf-8')
for line in f1:
    if '噢 昨日当我年少轻狂'in line:
        line = line.replace('噢 昨日当我年少轻狂','啦啦啦啦啦啦啦啦啦')
    f2.write(line)
f1.close()
f2.close()
要替换的文件:
Somehow, it seems the love I knew was always the most destructive kind
不知为何,我经历的爱情总是最具毁灭性的的那种
Yesterday when I was young
昨日当我年少轻狂
The taste of life was sweet
生命的滋味是甜的
As rain upon my tongue
就如舌尖上的雨露
I teased at life as if it were a foolish game
我戏弄生命 视其为愚蠢的游戏
The way the evening breeze
就如夜晚的微风
May tease the candle flame
逗弄蜡烛的火苗
The thousand dreams I dreamed
我曾千万次梦见
The splendid things I planned
那些我计划的绚丽蓝图
I always built to last on weak and shifting sand
但我总是将之建筑在易逝的流沙上
I lived by night and shunned the naked light of day
我夜夜笙歌 逃避白昼赤裸的阳光
And only now I see how the time ran away
事到如今我才看清岁月是如何匆匆流逝
Yesterday when I was young
昨日当我年少轻狂
So many lovely songs were waiting to be sung
有那么多甜美的曲儿等我歌唱
So many wild pleasures lay in store for me
有那么多肆意的快乐等我享受
And so much pain my eyes refused to see
还有那么多痛苦 我的双眼却视而不见
I ran so fast that time and youth at last ran out
我飞快地奔走 最终时光与青春消逝殆尽
I never stopped to think what life was all about
我从未停下脚步去思考生命的意义
And every conversation that I can now recall
如今回想起的所有对话
Concerned itself with me and nothing else at all
除了和我相关的 什么都记不得了
The game of love I played with arrogance and pride
我用自负和傲慢玩着爱情的游戏
And every flame I lit too quickly, quickly died
所有我点燃的火焰都熄灭得太快
The friends I made all somehow seemed to slip away
所有我交的朋友似乎都不知不觉地离开了
And only now I'm left alone to end the play, yeah
只剩我一个人在台上来结束这场闹剧
Oh, yesterday when I was young
噢 昨日当我年少轻狂
So many, many songs were waiting to be sung
有那么那么多甜美的曲儿等我歌唱
So many wild pleasures lay in store for me
有那么多肆意的快乐等我享受
And so much pain my eyes refused to see
还有那么多痛苦 我的双眼却视而不见
There are so many songs in me that won't be sung
我有太多歌曲永远不会被唱起
I feel the bitter taste of tears upon my tongue
我尝到了舌尖泪水的苦涩滋味
The time has come for me to pay for yesterday
终于到了付出代价的时间 为了昨日
When I was young
当我年少轻狂
python 3.x 写 shell sed 替换功能的更多相关文章
- Python3学习之路~2.8 文件操作实现简单的shell sed替换功能
		
程序:实现简单的shell sed替换功能 #实现简单的shell sed替换功能,保存为file_sed.py #打开命令行输入python file_sed.py 我 Alex,回车后会把文件中的 ...
 - 3-1 实现简单的shell sed替换功能
		
1.需求 程序1: 实现简单的shell sed替换功能 file1 的内容copy到file2 输入参数./sed.py $1 $2 $1替换成$2 (把a替换成% ) 2.个人思路 open ...
 - 4.实现简单的shell sed替换功能
		
# -*- coding:utf-8 -*- # Author: JACK ZHAO # 程序1: 实现简单的shell sed替换功能 import sys #判断参数个数 if len(sys.a ...
 - Python3.5 day3作业一:实现简单的shell sed替换功能
		
需求: 1.使python具有shell中sed替换功能. #!/usr/bin/env python #_*_conding:utf-8_*_ #sys模块用于传递参数,os模块用于与系统交互. i ...
 - python基础实现简单的shell sed 替换功能
		
#coding:utf-8 from pygame.draw import lines import sys,os old_file = sys.argv[1] #接受外部设备上的参数 new_fil ...
 - 实现简单的shell sed替换功能
		
通过脚本传参数可以实现替换 # -*-coding:utf-8-*- # Author:sunhao import sys f = open('yesterday','r',encoding='utf ...
 - 第11.23节  Python 中re模块的搜索替换功能:sub及subn函数
		
一. 引言 在<第11.3节 Python正则表达式搜索支持函数search.match.fullmatch.findall.finditer>重点介绍了几个搜索函数,除了搜索,re模块也 ...
 - 实现简单sed替换功能的python脚本
		
#可以用来修改配置文件参数 # -*- coding:utf-8 -*- import os,sys old = sys.argv[1] new = sys.argv[2] file = sys.ar ...
 - python中写shell(转)
		
python中写shell,亲测可用,转自stackoverflow To run a bash script, copy from stackoverflow def run_script(scri ...
 
随机推荐
- urlrewrite地址重写的使用
			
地址重写: 主要是为了站点的安全. 比如我们平时的地址请求 地址重写前,訪问路径是: /read.egov?action=read&bid=2 地址重写后,訪问路径是:/read-read-2 ...
 - 使用C++实现学生管理系统
			
我在前面的博客中分别使用C语言的动态数组和链表实现了学生成绩管理系统.近期正好在学习C++,于是我便使用C++实现了学生成绩管理系统.算法和前面的C语言的动态数组实现的学生成绩管理系统几乎相同,仅仅是 ...
 - leetcode第一刷_Add Binary
			
二进制相加,本质上就是大整数加法,有关大整数加法我的舍友教过我一个非常好的方法,先用一个int数组保存结果,将两个数相应位置相加,所有加完后.再统一处理进位的问题.这种方法相同适用于大整数的乘法. 这 ...
 - C++ Primer Plus的若干收获--(三)
			
有时候怀疑真是怀疑自己走的路究竟是不是正确的.作为一个土生土长数学系学生,却对数学毫无兴趣,没事的时候就喜欢躲在图书馆看看有关计算机的书.有时候期末考试时候会挂个一两门的数学专业课,有时候真希望数学课 ...
 - bzoj3444: 最后的晚餐(并查集+组合数学)
			
3444: 最后的晚餐 题目:传送门 题解: 考虑有解的情况: 直接上并查集,同一个联通块里的人一定要坐在一起的.不难发现其实对于每个联通块最多就只有两种排列方式,那就直接把大于等于两个人的联通块先去 ...
 - How To Do @Async in Spring--转
			
原文地址:http://www.baeldung.com/spring-async 1. Overview In this article, we’ll explore the asynchronou ...
 - Swift学习笔记(8):闭包
			
目录: 基本语法 尾随闭包 值捕获 自动闭包 闭包是自包含的函数代码块,闭包采取如下三种形式之一: ・全局函数是一个有名字但不会捕获任何值的闭包 ・嵌套函数是一个有名字并可以捕获其封闭函数域内值的闭包 ...
 - poj1170 - 转换成背包
			
题目链接 有5种物品,给出每个物品的单价. 给出几个这些物品的组合和这个组合的价格.买组合要比一件件的买便宜. 问给定的购买计划最少花多少钱. ---------------------------- ...
 - WebKit.NET-0.5简单应用(2)——音量解决方案
			
查找WebKit.NET相关文档,没有找到音量控制解决方法.换思路进行解决,尝试用Win32 API进行解决 [DllImport("winmm.dll")] public sta ...
 - dropload上拉加载 下拉刷新
			
1.引入css.js <link rel="stylesheet" href=" ${pageContext.request.contextPath}/dist/d ...