Python: How to read between two words from a text file in python2019 Community Moderator ElectionHow to merge two dictionaries in a single expression?How do I check whether a file exists without exceptions?Difference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?How to get the current time in PythonHow can I make a time delay in Python?How to concatenate two lists in Python?How do I list all files of a directory?How to read a file line-by-line into a list?Why is reading lines from stdin much slower in C++ than Python?

Fastest way to pop N items from a large dict

A single argument pattern definition applies to multiple-argument patterns?

Non-trivial topology where only open sets are closed

A diagram about partial derivatives of f(x,y)

PTIJ: Who should I vote for? (21st Knesset Edition)

Is it insecure to send a password in a `curl` command?

About the actual radiative impact of greenhouse gas emission over time

Does multi-classing into Fighter give you heavy armor proficiency?

Examples of transfinite towers

Knife as defense against stray dogs

Is there a place to find the pricing for things not mentioned in the PHB? (non-magical)

Does .bashrc contain syntax errors?

Explaining pyrokinesis powers

What is the meaning of まっちろけ?

If I can solve Sudoku, can I solve the Travelling Salesman Problem (TSP)? If so, how?

The meaning of 振り in 無茶振り

Employee lack of ownership

How can we have a quark condensate without a quark potential?

Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible

Different outputs for `w`, `who`, `whoami` and `id`

While on vacation my taxi took a longer route, possibly to scam me out of money. How can I deal with this?

Why is there is so much iron?

How could an airship be repaired midflight?

How to explain that I do not want to visit a country due to personal safety concern?



Python: How to read between two words from a text file in python



2019 Community Moderator ElectionHow to merge two dictionaries in a single expression?How do I check whether a file exists without exceptions?Difference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?How to get the current time in PythonHow can I make a time delay in Python?How to concatenate two lists in Python?How do I list all files of a directory?How to read a file line-by-line into a list?Why is reading lines from stdin much slower in C++ than Python?










-2















I have a txt file which is basically a question paper, I wanted to read that file and execute some operations between two words.



Let's say there are 3 parts, PART A, PART B, PART C, and I wanted to do some operations like check all the question numbers whether is it present between PART A and PART B.



Check this link of the question paper



I wanted to check whether all the 12 questions are present in part A section



To summarise I wanted to read only between two words within the txt file



This is the entire code.
im comparing between two question papers
Note: its raw code not completed



# Ask the user to enter the names of files to compare
fname1 = input("Enter the Blue print name: ")
fname2 = input("Enter the Source name: ")

# Open file for reading in text mode (default mode)
f1 = open(fname1)
f2 = open(fname2)

# Print confirmation
print("-----------------------------------")
print("Comparing files ", " BP " + fname1, " SRC " +fname2, sep='n')
print("-----------------------------------")

# Read the first line from the files
f1_line = f1.readline()
f2_line = f2.readline()

# Initialize counter for line number
line_no = 1
NoError=True
# Loop if either file1 or file2 has not reached EOF
while f1_line != '' or f2_line != '':

# Strip the leading whitespaces
f1_line = f1_line.rstrip()
f2_line = f2_line.rstrip()

# Compare the lines from both file
if f1_line != f2_line:

# If a line does not exist on file2 then mark the output with + sign
if f2_line == '' and f1_line != '':
NoError=False
print("Additional line found in BP", "Line-%d" % line_no, f1_line)
# otherwise output the line on file1 and mark it with > sign
elif f1_line != '':
print("Please check BP", "Line-%d" % line_no, f1_line)
NoError=False
# If a line does not exist on file1 then mark the output with + sign
if f1_line == '' and f2_line != '':
print("Additional line found in SRC ", "Line-%d" % line_no, f2_line)
NoError=False
# otherwise output the line on file2 and mark it with < sign
elif f2_line != '':
print("Please check SRC", "Line-%d" % line_no, f2_line)
NoError=False




#Read the next line from the file
f1_line = f1.readline()
f2_line = f2.readline()


#Increment line counter
line_no += 1
if NoError:
print("Both files are same")


print("---------------------------------------------------------------------n")
print("---------------------------------------------------------------------")
print("Checking for partsn")
print("-----------------------------------")

#Checking for parts
#Put the parts in as p1 for part A, p2 for part b etc.....
p1 = "Part A"
p2 = "Part B"
#Checking parts condition in Blue print file
if p1 in open(fname1).read():
print("Part A found in BP")
else:
print("Part A not found BP")


if p2 in open(fname1).read():
print("Part B found in BP")
else:
print("Part B not found BP")
#Checking parts condition in Source file
if p1 in open(fname2).read():
print("Part A found in Src")
else:
print("Part A not found Src")


if p2 in open(fname2).read():
print("Part B found in Src")
else:
print("Part B not found Src")

print("---------------------------------------------------------------------n")
print("---------------------------------------------------------------------")
print("Checking for questionsn")
print("---------BLUE PRINT---------")
print("PART A")

parta = [".".format(i+1) for i in range(12)]
found_alla = True

with open(fname1) as file:
text = file.read()
for word in parta:
if word not in text:
found_alla= False
print(" not foundn".format(word))

if found_alla:
print("all questions found in Part A of Blue printn")


print("PART B")

partb = ["".format(i+1) for i in range(5)]
found_allb = True

with open(fname1) as file:
text = file.read()
for word in partb:
if word not in text:
found_allb= False
print(" not foundn".format(word))

if found_allb:
print("all questions found in Part B of Blue print")


print("---------SOURCE---------")
print("PART A")

partas = [".".format(i+1) for i in range(12)]
found_allaS = True

with open(fname2) as file:
text = file.read()
for word in partas:
if word not in text:
found_allaS= False
print(" not foundn".format(word))

if found_allaS:
print("all questions found in Part A of SOURCEn")


print("PART B")

partbS = [".".format(i+1) for i in range(5)]
found_allBS = True

with open(fname2) as file:
text = file.read()
for word in partbS:
if word not in text:
found_allbS= False
print(" not foundn".format(word))

if found_allbS:
print("all questions found in Part B of SOURCE")

f1.close()
f2.close()

input("Press Enter to close")









share|improve this question
























  • @Mathieu I dint think to putup the txt file since it was clear that i wanted to perform actions between two words, no issues ill upload em

    – Appries
    Mar 7 at 15:53











  • @Mathieu i have added the txt file

    – Appries
    Mar 7 at 16:07















-2















I have a txt file which is basically a question paper, I wanted to read that file and execute some operations between two words.



Let's say there are 3 parts, PART A, PART B, PART C, and I wanted to do some operations like check all the question numbers whether is it present between PART A and PART B.



Check this link of the question paper



I wanted to check whether all the 12 questions are present in part A section



To summarise I wanted to read only between two words within the txt file



This is the entire code.
im comparing between two question papers
Note: its raw code not completed



# Ask the user to enter the names of files to compare
fname1 = input("Enter the Blue print name: ")
fname2 = input("Enter the Source name: ")

# Open file for reading in text mode (default mode)
f1 = open(fname1)
f2 = open(fname2)

# Print confirmation
print("-----------------------------------")
print("Comparing files ", " BP " + fname1, " SRC " +fname2, sep='n')
print("-----------------------------------")

# Read the first line from the files
f1_line = f1.readline()
f2_line = f2.readline()

# Initialize counter for line number
line_no = 1
NoError=True
# Loop if either file1 or file2 has not reached EOF
while f1_line != '' or f2_line != '':

# Strip the leading whitespaces
f1_line = f1_line.rstrip()
f2_line = f2_line.rstrip()

# Compare the lines from both file
if f1_line != f2_line:

# If a line does not exist on file2 then mark the output with + sign
if f2_line == '' and f1_line != '':
NoError=False
print("Additional line found in BP", "Line-%d" % line_no, f1_line)
# otherwise output the line on file1 and mark it with > sign
elif f1_line != '':
print("Please check BP", "Line-%d" % line_no, f1_line)
NoError=False
# If a line does not exist on file1 then mark the output with + sign
if f1_line == '' and f2_line != '':
print("Additional line found in SRC ", "Line-%d" % line_no, f2_line)
NoError=False
# otherwise output the line on file2 and mark it with < sign
elif f2_line != '':
print("Please check SRC", "Line-%d" % line_no, f2_line)
NoError=False




#Read the next line from the file
f1_line = f1.readline()
f2_line = f2.readline()


#Increment line counter
line_no += 1
if NoError:
print("Both files are same")


print("---------------------------------------------------------------------n")
print("---------------------------------------------------------------------")
print("Checking for partsn")
print("-----------------------------------")

#Checking for parts
#Put the parts in as p1 for part A, p2 for part b etc.....
p1 = "Part A"
p2 = "Part B"
#Checking parts condition in Blue print file
if p1 in open(fname1).read():
print("Part A found in BP")
else:
print("Part A not found BP")


if p2 in open(fname1).read():
print("Part B found in BP")
else:
print("Part B not found BP")
#Checking parts condition in Source file
if p1 in open(fname2).read():
print("Part A found in Src")
else:
print("Part A not found Src")


if p2 in open(fname2).read():
print("Part B found in Src")
else:
print("Part B not found Src")

print("---------------------------------------------------------------------n")
print("---------------------------------------------------------------------")
print("Checking for questionsn")
print("---------BLUE PRINT---------")
print("PART A")

parta = [".".format(i+1) for i in range(12)]
found_alla = True

with open(fname1) as file:
text = file.read()
for word in parta:
if word not in text:
found_alla= False
print(" not foundn".format(word))

if found_alla:
print("all questions found in Part A of Blue printn")


print("PART B")

partb = ["".format(i+1) for i in range(5)]
found_allb = True

with open(fname1) as file:
text = file.read()
for word in partb:
if word not in text:
found_allb= False
print(" not foundn".format(word))

if found_allb:
print("all questions found in Part B of Blue print")


print("---------SOURCE---------")
print("PART A")

partas = [".".format(i+1) for i in range(12)]
found_allaS = True

with open(fname2) as file:
text = file.read()
for word in partas:
if word not in text:
found_allaS= False
print(" not foundn".format(word))

if found_allaS:
print("all questions found in Part A of SOURCEn")


print("PART B")

partbS = [".".format(i+1) for i in range(5)]
found_allBS = True

with open(fname2) as file:
text = file.read()
for word in partbS:
if word not in text:
found_allbS= False
print(" not foundn".format(word))

if found_allbS:
print("all questions found in Part B of SOURCE")

f1.close()
f2.close()

input("Press Enter to close")









share|improve this question
























  • @Mathieu I dint think to putup the txt file since it was clear that i wanted to perform actions between two words, no issues ill upload em

    – Appries
    Mar 7 at 15:53











  • @Mathieu i have added the txt file

    – Appries
    Mar 7 at 16:07













-2












-2








-2








I have a txt file which is basically a question paper, I wanted to read that file and execute some operations between two words.



Let's say there are 3 parts, PART A, PART B, PART C, and I wanted to do some operations like check all the question numbers whether is it present between PART A and PART B.



Check this link of the question paper



I wanted to check whether all the 12 questions are present in part A section



To summarise I wanted to read only between two words within the txt file



This is the entire code.
im comparing between two question papers
Note: its raw code not completed



# Ask the user to enter the names of files to compare
fname1 = input("Enter the Blue print name: ")
fname2 = input("Enter the Source name: ")

# Open file for reading in text mode (default mode)
f1 = open(fname1)
f2 = open(fname2)

# Print confirmation
print("-----------------------------------")
print("Comparing files ", " BP " + fname1, " SRC " +fname2, sep='n')
print("-----------------------------------")

# Read the first line from the files
f1_line = f1.readline()
f2_line = f2.readline()

# Initialize counter for line number
line_no = 1
NoError=True
# Loop if either file1 or file2 has not reached EOF
while f1_line != '' or f2_line != '':

# Strip the leading whitespaces
f1_line = f1_line.rstrip()
f2_line = f2_line.rstrip()

# Compare the lines from both file
if f1_line != f2_line:

# If a line does not exist on file2 then mark the output with + sign
if f2_line == '' and f1_line != '':
NoError=False
print("Additional line found in BP", "Line-%d" % line_no, f1_line)
# otherwise output the line on file1 and mark it with > sign
elif f1_line != '':
print("Please check BP", "Line-%d" % line_no, f1_line)
NoError=False
# If a line does not exist on file1 then mark the output with + sign
if f1_line == '' and f2_line != '':
print("Additional line found in SRC ", "Line-%d" % line_no, f2_line)
NoError=False
# otherwise output the line on file2 and mark it with < sign
elif f2_line != '':
print("Please check SRC", "Line-%d" % line_no, f2_line)
NoError=False




#Read the next line from the file
f1_line = f1.readline()
f2_line = f2.readline()


#Increment line counter
line_no += 1
if NoError:
print("Both files are same")


print("---------------------------------------------------------------------n")
print("---------------------------------------------------------------------")
print("Checking for partsn")
print("-----------------------------------")

#Checking for parts
#Put the parts in as p1 for part A, p2 for part b etc.....
p1 = "Part A"
p2 = "Part B"
#Checking parts condition in Blue print file
if p1 in open(fname1).read():
print("Part A found in BP")
else:
print("Part A not found BP")


if p2 in open(fname1).read():
print("Part B found in BP")
else:
print("Part B not found BP")
#Checking parts condition in Source file
if p1 in open(fname2).read():
print("Part A found in Src")
else:
print("Part A not found Src")


if p2 in open(fname2).read():
print("Part B found in Src")
else:
print("Part B not found Src")

print("---------------------------------------------------------------------n")
print("---------------------------------------------------------------------")
print("Checking for questionsn")
print("---------BLUE PRINT---------")
print("PART A")

parta = [".".format(i+1) for i in range(12)]
found_alla = True

with open(fname1) as file:
text = file.read()
for word in parta:
if word not in text:
found_alla= False
print(" not foundn".format(word))

if found_alla:
print("all questions found in Part A of Blue printn")


print("PART B")

partb = ["".format(i+1) for i in range(5)]
found_allb = True

with open(fname1) as file:
text = file.read()
for word in partb:
if word not in text:
found_allb= False
print(" not foundn".format(word))

if found_allb:
print("all questions found in Part B of Blue print")


print("---------SOURCE---------")
print("PART A")

partas = [".".format(i+1) for i in range(12)]
found_allaS = True

with open(fname2) as file:
text = file.read()
for word in partas:
if word not in text:
found_allaS= False
print(" not foundn".format(word))

if found_allaS:
print("all questions found in Part A of SOURCEn")


print("PART B")

partbS = [".".format(i+1) for i in range(5)]
found_allBS = True

with open(fname2) as file:
text = file.read()
for word in partbS:
if word not in text:
found_allbS= False
print(" not foundn".format(word))

if found_allbS:
print("all questions found in Part B of SOURCE")

f1.close()
f2.close()

input("Press Enter to close")









share|improve this question
















I have a txt file which is basically a question paper, I wanted to read that file and execute some operations between two words.



Let's say there are 3 parts, PART A, PART B, PART C, and I wanted to do some operations like check all the question numbers whether is it present between PART A and PART B.



Check this link of the question paper



I wanted to check whether all the 12 questions are present in part A section



To summarise I wanted to read only between two words within the txt file



This is the entire code.
im comparing between two question papers
Note: its raw code not completed



# Ask the user to enter the names of files to compare
fname1 = input("Enter the Blue print name: ")
fname2 = input("Enter the Source name: ")

# Open file for reading in text mode (default mode)
f1 = open(fname1)
f2 = open(fname2)

# Print confirmation
print("-----------------------------------")
print("Comparing files ", " BP " + fname1, " SRC " +fname2, sep='n')
print("-----------------------------------")

# Read the first line from the files
f1_line = f1.readline()
f2_line = f2.readline()

# Initialize counter for line number
line_no = 1
NoError=True
# Loop if either file1 or file2 has not reached EOF
while f1_line != '' or f2_line != '':

# Strip the leading whitespaces
f1_line = f1_line.rstrip()
f2_line = f2_line.rstrip()

# Compare the lines from both file
if f1_line != f2_line:

# If a line does not exist on file2 then mark the output with + sign
if f2_line == '' and f1_line != '':
NoError=False
print("Additional line found in BP", "Line-%d" % line_no, f1_line)
# otherwise output the line on file1 and mark it with > sign
elif f1_line != '':
print("Please check BP", "Line-%d" % line_no, f1_line)
NoError=False
# If a line does not exist on file1 then mark the output with + sign
if f1_line == '' and f2_line != '':
print("Additional line found in SRC ", "Line-%d" % line_no, f2_line)
NoError=False
# otherwise output the line on file2 and mark it with < sign
elif f2_line != '':
print("Please check SRC", "Line-%d" % line_no, f2_line)
NoError=False




#Read the next line from the file
f1_line = f1.readline()
f2_line = f2.readline()


#Increment line counter
line_no += 1
if NoError:
print("Both files are same")


print("---------------------------------------------------------------------n")
print("---------------------------------------------------------------------")
print("Checking for partsn")
print("-----------------------------------")

#Checking for parts
#Put the parts in as p1 for part A, p2 for part b etc.....
p1 = "Part A"
p2 = "Part B"
#Checking parts condition in Blue print file
if p1 in open(fname1).read():
print("Part A found in BP")
else:
print("Part A not found BP")


if p2 in open(fname1).read():
print("Part B found in BP")
else:
print("Part B not found BP")
#Checking parts condition in Source file
if p1 in open(fname2).read():
print("Part A found in Src")
else:
print("Part A not found Src")


if p2 in open(fname2).read():
print("Part B found in Src")
else:
print("Part B not found Src")

print("---------------------------------------------------------------------n")
print("---------------------------------------------------------------------")
print("Checking for questionsn")
print("---------BLUE PRINT---------")
print("PART A")

parta = [".".format(i+1) for i in range(12)]
found_alla = True

with open(fname1) as file:
text = file.read()
for word in parta:
if word not in text:
found_alla= False
print(" not foundn".format(word))

if found_alla:
print("all questions found in Part A of Blue printn")


print("PART B")

partb = ["".format(i+1) for i in range(5)]
found_allb = True

with open(fname1) as file:
text = file.read()
for word in partb:
if word not in text:
found_allb= False
print(" not foundn".format(word))

if found_allb:
print("all questions found in Part B of Blue print")


print("---------SOURCE---------")
print("PART A")

partas = [".".format(i+1) for i in range(12)]
found_allaS = True

with open(fname2) as file:
text = file.read()
for word in partas:
if word not in text:
found_allaS= False
print(" not foundn".format(word))

if found_allaS:
print("all questions found in Part A of SOURCEn")


print("PART B")

partbS = [".".format(i+1) for i in range(5)]
found_allBS = True

with open(fname2) as file:
text = file.read()
for word in partbS:
if word not in text:
found_allbS= False
print(" not foundn".format(word))

if found_allbS:
print("all questions found in Part B of SOURCE")

f1.close()
f2.close()

input("Press Enter to close")






python python-3.x python-import readline






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 16:13







Appries

















asked Mar 7 at 15:41









AppriesAppries

255




255












  • @Mathieu I dint think to putup the txt file since it was clear that i wanted to perform actions between two words, no issues ill upload em

    – Appries
    Mar 7 at 15:53











  • @Mathieu i have added the txt file

    – Appries
    Mar 7 at 16:07

















  • @Mathieu I dint think to putup the txt file since it was clear that i wanted to perform actions between two words, no issues ill upload em

    – Appries
    Mar 7 at 15:53











  • @Mathieu i have added the txt file

    – Appries
    Mar 7 at 16:07
















@Mathieu I dint think to putup the txt file since it was clear that i wanted to perform actions between two words, no issues ill upload em

– Appries
Mar 7 at 15:53





@Mathieu I dint think to putup the txt file since it was clear that i wanted to perform actions between two words, no issues ill upload em

– Appries
Mar 7 at 15:53













@Mathieu i have added the txt file

– Appries
Mar 7 at 16:07





@Mathieu i have added the txt file

– Appries
Mar 7 at 16:07












2 Answers
2






active

oldest

votes


















0














I might be over simplifying this, but can you not just split at the headers to get what you need?



text = 'PART A: This is Part A, ham and eggs. PART B: This is part B, eggs and ham'

text.split('PART A:')[1].split('PART B:')[0].strip()


Resulting in:



'This is Part A, ham and eggs.'





share|improve this answer























  • Thank you, it's working... What I did is text=file.read().split("PART A")[1].split("PART B")[0].strip()

    – Appries
    Mar 7 at 21:25


















0














You may first search using some if statements that on which line do the word come .



Then make a loop between the lines and operate as you wish.



For example if PART 1 comes on line 10 and PART 2 comes on line 18 then make a loop between lines 10 and 18 and operate as you wish.






share|improve this answer























  • can you read the description again and present the code!!!

    – Appries
    Mar 7 at 16:05










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047654%2fpython-how-to-read-between-two-words-from-a-text-file-in-python%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I might be over simplifying this, but can you not just split at the headers to get what you need?



text = 'PART A: This is Part A, ham and eggs. PART B: This is part B, eggs and ham'

text.split('PART A:')[1].split('PART B:')[0].strip()


Resulting in:



'This is Part A, ham and eggs.'





share|improve this answer























  • Thank you, it's working... What I did is text=file.read().split("PART A")[1].split("PART B")[0].strip()

    – Appries
    Mar 7 at 21:25















0














I might be over simplifying this, but can you not just split at the headers to get what you need?



text = 'PART A: This is Part A, ham and eggs. PART B: This is part B, eggs and ham'

text.split('PART A:')[1].split('PART B:')[0].strip()


Resulting in:



'This is Part A, ham and eggs.'





share|improve this answer























  • Thank you, it's working... What I did is text=file.read().split("PART A")[1].split("PART B")[0].strip()

    – Appries
    Mar 7 at 21:25













0












0








0







I might be over simplifying this, but can you not just split at the headers to get what you need?



text = 'PART A: This is Part A, ham and eggs. PART B: This is part B, eggs and ham'

text.split('PART A:')[1].split('PART B:')[0].strip()


Resulting in:



'This is Part A, ham and eggs.'





share|improve this answer













I might be over simplifying this, but can you not just split at the headers to get what you need?



text = 'PART A: This is Part A, ham and eggs. PART B: This is part B, eggs and ham'

text.split('PART A:')[1].split('PART B:')[0].strip()


Resulting in:



'This is Part A, ham and eggs.'






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 at 15:52









RockHardRacoonRockHardRacoon

614110




614110












  • Thank you, it's working... What I did is text=file.read().split("PART A")[1].split("PART B")[0].strip()

    – Appries
    Mar 7 at 21:25

















  • Thank you, it's working... What I did is text=file.read().split("PART A")[1].split("PART B")[0].strip()

    – Appries
    Mar 7 at 21:25
















Thank you, it's working... What I did is text=file.read().split("PART A")[1].split("PART B")[0].strip()

– Appries
Mar 7 at 21:25





Thank you, it's working... What I did is text=file.read().split("PART A")[1].split("PART B")[0].strip()

– Appries
Mar 7 at 21:25













0














You may first search using some if statements that on which line do the word come .



Then make a loop between the lines and operate as you wish.



For example if PART 1 comes on line 10 and PART 2 comes on line 18 then make a loop between lines 10 and 18 and operate as you wish.






share|improve this answer























  • can you read the description again and present the code!!!

    – Appries
    Mar 7 at 16:05















0














You may first search using some if statements that on which line do the word come .



Then make a loop between the lines and operate as you wish.



For example if PART 1 comes on line 10 and PART 2 comes on line 18 then make a loop between lines 10 and 18 and operate as you wish.






share|improve this answer























  • can you read the description again and present the code!!!

    – Appries
    Mar 7 at 16:05













0












0








0







You may first search using some if statements that on which line do the word come .



Then make a loop between the lines and operate as you wish.



For example if PART 1 comes on line 10 and PART 2 comes on line 18 then make a loop between lines 10 and 18 and operate as you wish.






share|improve this answer













You may first search using some if statements that on which line do the word come .



Then make a loop between the lines and operate as you wish.



For example if PART 1 comes on line 10 and PART 2 comes on line 18 then make a loop between lines 10 and 18 and operate as you wish.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 at 15:52









Gursewak DhindsaGursewak Dhindsa

351




351












  • can you read the description again and present the code!!!

    – Appries
    Mar 7 at 16:05

















  • can you read the description again and present the code!!!

    – Appries
    Mar 7 at 16:05
















can you read the description again and present the code!!!

– Appries
Mar 7 at 16:05





can you read the description again and present the code!!!

– Appries
Mar 7 at 16:05

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047654%2fpython-how-to-read-between-two-words-from-a-text-file-in-python%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived