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

The Archive Base Latest Questions

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

I have written a set of Python 3 scripts to take a formatted text

  • 0

I have written a set of Python 3 scripts to take a formatted text file and move the data into a SQLite database. The data in the database is then used as a part of a PHP application. The data in my text file has formatting markers for bold and italics, but not in anything intelligible to a browser. The formatting scheme is like this:

fi:xxxx        (italics on the word xxxx (turned off at the word break))
fi:{xxx…xxx}   (italics on the word or phrase in the curly brackets {})
fb:xxxx        (bold on the word xxxx (turned off at the word break))
fb:{xxx}       (bold on the word or phrase in the brackets {})
fv:xxxx        (bold on the word xxxx (turned off at the word break))
fv:{xxx…xxx}   (bold on the word or phrase in the brackets {})
fn:{xxx…xxx}   (no formatting)

I would like to convert each line of source text to (1. a line containing the string, using html tags instead of the source formatting and 2. another line, containing the string stripped of all formatting markers). I need a formatted and a stripped line for each source line, even if no formatting markers are used on that line. In the source data, multiple formatting markers of different (or the same) sort may show up in a single line, but you won’t find any marker that doesn’t end before the line does.

  • 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:47:48+00:00Added an answer on May 23, 2026 at 4:47 pm

    To format the bracketed sections, you could do something like this:

    while text.find(":{") > -1:
        index = text.find(":{")
        if text[index-2:index]=="fb":
            text = text[:index-2] + "<b>" + text[index+2:] #insert <b>
            text = text.replace("}","</b>",1) # replace one.
        # else if fi, fv, etc.
    

    This will convert “other fb:{bold text} text” to “other bold text text”.

    Then you could convert the space-separated sections:

    array = text.split(" ")
    for word in array:
        if (word.startswith("fi")):
            word = "<i>"+word[2:]+"</i>"
        else if (word.startswith("fb")):
            ....
    text = " ".join(array)
    

    If you want plain text just replace the tags such as “<b>” and “</b>” with empty string “”.

    If the formatting doesn’t span multiple lines you will probably get better performance reading and converting line by line with:

    inFile = open("file.txt","r")
    outFile = open("file.out","w")
    
    def convert(text):
        #Change text here.
        return text
    
    for line in inFile:
        outFile.write(convert(line))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In README file of omniORBpy-3.4 is written that I have to set PYTHONPATH as
I have written a python script to process a set of ASCII files within
I have written a python daemon that continuously polls a mysql database. It works
I have written a set of classes and interfaces that are implemented in Moose
I have written a method to calculate a given percentile for a set of
I would to take in some login information for a script have written in
I have written a small Python application where I use PyGame for displaying some
I have written a set of Win32 dlls that encapsulate a Delphi Frame (see
Greetings. I have written a little python script that calls MySQL in a subprocess.
I have an installation script written in Python (in Linux) that runs as root

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.