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

The Archive Base Latest Questions

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

I just want to make sure I’m doing this in the proper pythonic way

  • 0

I just want to make sure I’m doing this in the proper “pythonic” way – I want to make sure I’ve defind – and am using – this exception class correctly. Especially the eval(repr()) logic – it’s mostly for cleanliness, I understand why you end up with quotes around the string repr() returns, but I don’t like to log them.

class IPCClientError(Exception):
    """ General IPC Client Exception class """
    def __init__(self, value = "Unspecified error"):
        self.val = value + ", see IPC client log for details."

    def __str__(self):
        return eval(repr(self.val))

When I raise the exception, I use something like:

raise IPCClientError("Socket error")

And then the calling method will have something like this:

except IPCClientError, exc:
    self.log.error(str(exc))
    return ERROR
  • 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-25T03:30:11+00:00Added an answer on May 25, 2026 at 3:30 am
    eval(repr(self.val))
    

    Eek, what are you trying to accomplish here? isn’t self.val already supposed to be a string?

    The way to avoid the quotes that repr attaches is not to use it in the first place.

    If you’re worried that the value passed to the constructor won’t be a string, well – that will fail in the constructor (unicode quibbles notwithstanding) anyway and you’ll just get a TypeError raised before your custom exception can be.

    As for how you handle the exception, exception handling is kind of an art, and really not something that can be covered in this space…

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

Sidebar

Related Questions

I just want to make sure if I am doing this correct. I am
Just want to make sure this is the best way to call a connection,
I Just want to make sure I understand this correctly... search is an object
Just want to make sure I understand this correctly (I'd ask on SO Chat,
I am doing a md5 hash, and just want to make sure the result
I just want to make sure I'm understanding the documentation correctly. If I add
I know this question is silly but I just want to make sure. Does
from my testing, this is true, but i just want to make sure it
Just curious if this is the way to do this, just want to make
Just want to make sure my test code below is proper. I've been reading

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.