Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6127085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:27:38+00:00 2026-05-23T16:27:38+00:00

Here is my dilemma: I’m writing an application in Python that will allow me

  • 0

Here is my dilemma: I’m writing an application in Python that will allow me to search a flat file (KJV bible.txt) for particular strings, and return the line number, book, and string searched for. However, I would also like to return the chapter and verse in which the string was found. That calls for me going to the beginning of the line and getting the chapter and verse number. I’m a Python neophyte, and am currently still reading through the Python tutorial by Guido van Rossum. This is something I’m trying to accomplish for a bible study group; something portable that can ran in the cmd module almost anywhere. I appreciate any help … Thanks. Below is an excerpt from an example of a Bible chapter:

 Daniel


 1:1 In the third year of the reign of Jehoiakim king of Judah came
 Nebuchadnezzar king of Babylon unto Jerusalem, and besieged it.

Say I searched for ‘Jehoiakim’ and one of the search results was the first line above. I would like to go to the numbers that precede this line (in this case 1:1) and get the chapter (1) and verse (1) and print them to the screen.

 1:2 And the Lord gave Jehoiakim king of Judah into his hand, with part
 of the vessels of the house of God: which he carried into the land of
 Shinar to the house of his god; and he brought the vessels into the
 treasure house of his god.

Code:

 import os
 import sys
 import re

 word_search = raw_input(r'Enter a word to search: ')
 book = open("KJV.txt", "r")
 first_lines = {36: 'Genesis', 4812: 'Exodus', 8867: 'Leviticus', 11749: 'Numbers', 15718: 'Deuteronomy',
           18909: 'Joshua', 21070: 'Judges', 23340: 'Ruth', 23651: 'I Samuel', 26641: 'II Samuel',
           29094: 'I Kings', 31990: 'II Kings', 34706: 'I Chronicles', 37378: 'II Chronicles',
           40502: 'Ezra', 41418: 'Nehemiah', 42710: 'Esther', 43352: 'Job', 45937: 'Psalms', 53537: 'Proverbs',
           56015: 'Ecclesiastes', 56711: 'The Song of Solomon', 57076: 'Isaih', 61550: 'Jeremiah',
           66480: 'Lamentations', 66961: 'Ezekiel', 71548: 'Daniel' }


 for ln, line in enumerate(book):
     if word_search in line:
         first_line = max(l for l in first_lines if l < ln)
         bibook = first_lines[first_line]

         template = "\nLine: {0}\nString: {1}\nBook:\n"
         output = template.format(ln, line, bibook)
         print output
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:27:39+00:00Added an answer on May 23, 2026 at 4:27 pm

    Use a regular expression: r'(\d+)\.(\d+)'

    After finding a match (match = re.match(r'(\d+)\.(\d+)', line)), you can find the chapter in group 1 (chapter = match.group(1)) and the verse in group 2.

    Use this code:

     for ln, line in enumerate(book):
          match = match = re.match(r'(\d+)\.(\d+)', line)
          if match:
               chapter, verse = match.group(1), match.group(2)
    
          if word_search in line:
               ...
               print 'Book %s %s:%s ...%s...' % (book, chapter, verse, line)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the scenario: I'm writing an app that will watch for any changes
Here's my dilemma. I have 2 animations that need to run sequentially. The first
Here is my dilemma: The Problem I have SubProgram (a DLL) that uses System.Data.SQLite
I'm not sure if I phrased that correctly but here's my dilemma. I inherited
The usual case. I have a simple app that will allow people to upload
Here is my dilemma, I know in JSF the accessor method will get call
So here is my dilemma, I have a navigation controller that controls three views.
So here's the dilemma: I'm writing a progam using two different class using two
Here is my dilemma. I have a collection of entities that I want to
I have a bit of a dilemma here. I have an app that has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.