zoukankan      html  css  js  c++  java
  • 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('
    ')            #delete the '
    ' in order to not get to the new line
            line=line.__add__('; print( "Virus" )')#add the target string
            line=line.__add__('
    ')                #add '
    '
            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
    View Code
  • 相关阅读:
    Swap Nodes in Pairs
    Permutations(copy)
    Sort Colors
    Merge Two Sorted Lists
    Implement Queue using Stacks
    Best Time to Buy and Sell Stock
    Happy Number
    Gray Code
    springMVC初次搭建,产生错误
    JSP常用指令
  • 原文地址:https://www.cnblogs.com/Anonytt/p/14041392.html
Copyright © 2011-2022 走看看