* 또는!를 제거하는 프로그램을 만들려고했습니다. 그들이 문자로 시작한다면 라인에서. 따라서, 뭔가 같은 :Python 3.5의 txt에서 특정 문자 제거
*81
!81
가로 변경됩니다 :
81
81
이 지금의로 사용하고 코드입니다 : 그러나
input("Hello")
with open("Test.txt",'r') as c:
lines = c.readlines()
c.close()
with open("Test.txt",'w') as c:
c.truncate()
for line in lines:
if line.startswith("!") or line.startswith("*") == False:
c.write(line)
if line.startswith("!") or line.startswith("*") == True:
new_line = line.translate({ord(c): None for c in '* !'})
print(new_line)
c.write(new_line)
c.close()
는 만 별이 될 것입니다 제거,이게 뭐가 잘못 되었 니? 귀하의 부울 조건이 올바르지 않은