-4
매 10-12 줄 끝에 페이지 번호가있는 텍스트 문서를 편집하고 싶습니다 (PDF를 텍스트로 변환하고 페이지 끝에서 페이지 번호가 있음). 페이지 번호 50이 가능할뿐만 아니라 정수로 50이 될 수있는 행이 될 수 있으므로 텍스트의 특정 페이지 번호 정수를 제거하고 싶습니다. 따라서 페이지 번호가 정수 인 행만 제거하고 싶습니다. 텍스트 문서의파이썬에서 라인을 읽고 라인을 제거하는 법?
예 :
1
militant Muslims use scriptures such as the
Genesis story describing the destruction of
Sodom and Gomorrah as justification (from Allah)
for the hatred they vent on all things non-
Muslim and especially on gay men.
2
A Word from the Author
Today, in the 21st Century the majority of Muslims
hold middle
3
Into The Darkness
the driver assured the exhausted travelers who
were dozing fitfully in the rear of the van, they
4
down. It blocked the narrow road.
Ali Azzizi was the other man accompanying
the women.
5
나는 제거 1-5에서 이러한 페이지 번호를 원하지만이 같은 수의 라인 사이에 어디서든 나타날 경우 제거해서는 안된다. 파이썬의 사용이 필수가 아닌 경우
내 코드
filename = input('filname')
filedata = None
temp = 1
with open(filename, 'r', encoding="utf8") as file:
filedata = file.read()
filedata.join(line.strip() for line in file)
rahul = ' '
for line in file:
if(line=='1'):
filedata = filedata.replace(line, ' ')
with open(filename, 'w', encoding="utf8") as file:
file.write(filedata)
코드가 있습니까? 여기서 물어보기 전에 적어도 스스로 문제를 해결하려고 노력해야합니다. 제거 할 숫자가 새 줄 사이에있는 것처럼 보이기 때문에 정규식을 사용할 수 있습니다 (숫자 5 제외 ...). – user2393256
지금까지 시도한 것은 무엇입니까? 당신이 겪고있는 문제는 어디에 있습니까? [파일 읽기?] (https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files) [유형 감지 중] (http://stackoverflow.com/questions/2225038)/결정 - the-python 개체의 유형). 당신이 이미 노력을 기울인 것을 보여주십시오 ... –
모든 것을 메모리에 읽고, 텍스트를 편집하고, 모든 것을 파일에 씁니다. 또는 lin-by-line을 읽고 새로운 file.And 나중에 오래된 파일을 삭제하고, 새로운 파일의 이름을 이전 이름으로 바꿉니다. – furas