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 3974520
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:34:38+00:00 2026-05-20T04:34:38+00:00

In Python, it possible to cut out a section of text in a document

  • 0

In Python, it possible to cut out a section of text in a document when you only know the beginning and end words?

For example, using the bill of rights as the sample document, search for “Amendment 3” and remove all the text until you hit “Amendment 4” without actually knowing or caring what text exists between the two end points.

The reason I’m asking is I would like to use this Python script to modify my other Python programs when I upload them to the client’s computer — removing sections of code that exists between a comment that says “#chop-begin” and “#chop-end”. I do not want the client to have access to all of the functions without paying for the better version of the code.

  • 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-20T04:34:39+00:00Added an answer on May 20, 2026 at 4:34 am

    You can use Python’s re module.

    I wrote this example script for removing the sections of code in file:

    import re
    
    # Create regular expression pattern
    chop = re.compile('#chop-begin.*?#chop-end', re.DOTALL)
    
    # Open file
    f = open('data', 'r')
    data = f.read()
    f.close()
    
    # Chop text between #chop-begin and #chop-end
    data_chopped = chop.sub('', data)
    
    # Save result
    f = open('data', 'w')
    f.write(data_chopped)
    f.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: python: how to jump to a particular line in a huge text
Is it possible to open an mp3 file in Python (possible using Popen )
Possible Duplicate: Python analog of natsort function (sort a list using a “natural order”
Possible Duplicate: Python: How to read huge text file into memory To process a
I already created a txt file using python with a few lines of text
Possible Duplicate: Python : how to append new elements in a list of list?
Possible Duplicate: Python: What is the best way to check if a list is
Possible Duplicate: Python: Get object by id Typically when you see the string representation
Possible Duplicate: Python: Behaviour of increment and decrement operators >>> a=2 >>> ++a 2
Is it possible in python to tell if a full screen application on linux

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.