Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
89 views
in Technique[技术] by (71.8m points)

python - Get value after blank line


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm not sure what you're trying to do

but I guess you want to tokenize your text and then strip each token if that so here what you could do

with open("file.txt", "r") as f:
    tokens = f.read().split(" ")

tokens = [item.strip() for item in data]

EDIT

with open("file.txt", "r") as f:
    lines = f.read().split("
")
    Flag = False
    FirstPart = [] 
    LastPart = []
    for line in lines:
        if len(line) == 0:
            Flag = True
        if not Flag:
            FirstPart.append(line)
        else:
            LastPart.append(line)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...