py_assignment1
################################################################# # my program's method to achieve the mission is by through # # creating a new file --"temp.py" to record the modify results # # and then to delete the previous target file--"sys.py" # # after that we rename the "temp.py" as "sys.py" # ################################################################# import os file = open("sfs.py",'r') #open the target file which is "sfs.py" f = open("temp.py",'w') #create a new file for recording the modify results cnt=0; #count the lines for line in file.readlines(): cnt=cnt+1; if(cnt!=52) : f.write(line) if cnt==52 : line=line.strip('\n') #delete the '\n' in order to not get to the new line line=line.__add__('; print( "Virus" )')#add the target string line=line.__add__('\n') #add '\n' f.write(line) file.close() #close the target file f.close() #close the modify file os.remove("sfs.py") #delete the target file os.rename("temp.py", "sfs.py")#rename the modify file's name as previous target file
前ICPC算法竞赛退役选手|现摸鱼ing