Replace four letter word in python

前端 未结 5 964
暗喜
暗喜 2020-12-12 08:24

I am trying to write a program that opens a text document and replaces all four letter words with **. I have been messing around with this program for multiple hour

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-12 08:44

    You need replace the letter w in w+ on line 4: file1 = open(filename, 'w') haves to be file1 = open(filename, 'w+') (I was working on this project too so this was my code)

    import os
    import time
    localtime = time.asctime( time.localtime(time.time()) )
    a = input("What is your first name?   ").title()
    b = input("And your last name?   ").title()
    c = input("What is your e-mail adderess?   ")
    d = input("And your phone number?   ")
    f = input("When were you born? (02-01-1900 is 1 February 1900)")
    print(a)
    print(b)
    print(c)
    print(d)
    print(f)
    e = input("Is this correct? (Y\N)  ")
    g = (a+"-"+b)
    
    
    
    
    if e == "Y" or "y":
        new_path = '/users/Pivo/registreren/%s.txt' % g
        new_days = open(new_path,'w+')
        new_days.write(localtime)
        new_days.write('\n')
        new_days.write(a)
        new_days.write(" ")
        new_days.write(b)
        new_days.write('\n')
        new_days.write(c)
        new_days.write('\n')
        new_days.write(d)
        new_days.write('\n')
        new_days.write(f)
        new_days.write('\n')
        new_days.write('\n')
        new_days.write('\n')
        new_days.write('\n')
        new_days.close()
        print("Okay, done!")
    if e == "N" or "n":
        os.startfile("C:/Users/Pivo/registreren/registreren.py")
    

提交回复
热议问题