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

  • Home
  • SEARCH
  • 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 62677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:30:48+00:00 2026-05-10T18:30:48+00:00

I have a python script that analyzes a set of error messages and checks

  • 0

I have a python script that analyzes a set of error messages and checks for each message if it matches a certain pattern (regular expression) in order to group these messages. For example ‘file x does not exist’ and ‘file y does not exist’ would match ‘file .* does not exist’ and be accounted as two occurrences of ‘file not found’ category.

As the number of patterns and categories is growing, I’d like to put these couples ‘regular expression/display string’ in a configuration file, basically a dictionary serialization of some sort.

I would like this file to be editable by hand, so I’m discarding any form of binary serialization, and also I’d rather not resort to xml serialization to avoid problems with characters to escape (& <> and so on…).

Do you have any idea of what could be a good way of accomplishing this?

Update: thanks to Daren Thomas and Federico Ramponi, but I cannot have an external python file with possibly arbitrary 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. 2026-05-10T18:30:48+00:00Added an answer on May 10, 2026 at 6:30 pm

    You have two decent options:

    1. Python standard config file format using ConfigParser
    2. YAML using a library like PyYAML

    The standard Python configuration files look like INI files with [sections] and key : value or key = value pairs. The advantages to this format are:

    • No third-party libraries necessary
    • Simple, familiar file format.

    YAML is different in that it is designed to be a human friendly data serialization format rather than specifically designed for configuration. It is very readable and gives you a couple different ways to represent the same data. For your problem, you could create a YAML file that looks like this:

    file .* does not exist : file not found user .* not found : authorization error 

    Or like this:

    { file .* does not exist: file not found,   user .* not found: authorization error } 

    Using PyYAML couldn’t be simpler:

    import yaml  errors = yaml.load(open('my.yaml')) 

    At this point errors is a Python dictionary with the expected format. YAML is capable of representing more than dictionaries: if you prefer a list of pairs, use this format:

    -   - file .* does not exist    - file not found -   - user .* not found   - authorization error 

    Or

    [ [file .* does not exist, file not found],   [user .* not found, authorization error]] 

    Which will produce a list of lists when yaml.load is called.

    One advantage of YAML is that you could use it to export your existing, hard-coded data out to a file to create the initial version, rather than cut/paste plus a bunch of find/replace to get the data into the right format.

    The YAML format will take a little more time to get familiar with, but using PyYAML is even simpler than using ConfigParser with the advantage is that you have more options regarding how your data is represented using YAML.

    Either one sounds like it will fit your current needs, ConfigParser will be easier to start with while YAML gives you more flexibilty in the future, if your needs expand.

    Best of luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 115k
  • Answers 115k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Nope. That's pretty good. From The Zen of Python: "Simple… May 11, 2026 at 10:28 pm
  • Editorial Team
    Editorial Team added an answer If the column has a 0 value, you are fine,… May 11, 2026 at 10:28 pm
  • Editorial Team
    Editorial Team added an answer Hook up an event handler for the Paint event of… May 11, 2026 at 10:28 pm

Related Questions

I work a lot with serial communications with a variety of devices, and so
I have a Python script that needs to execute an external program, but for
I have a python script that is a http-server: http://paste2.org/p/89701 , when benchmarking it
I have a python script that I would like to add a Shutdown when

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.