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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:14:42+00:00 2026-05-11T22:14:42+00:00

Update: This is, as I was told, no principle Python related problem, but seems

  • 0

Update: This is, as I was told, no principle Python related problem, but seems to be more specific. See below for more explanations to my problem.

I have a custom exception (let’s call it CustomException), that lives in a file named exceptions.py. Now imagine, that I can import this file via two paths:

import application.exceptions

or

import some.application.exceptions

with the same result. Furthermore I have no control over which way the module is imported in other modules.

Now to show my problem: Assume that the function do_something comes from another module that imports exceptions.py in a way I don’t know. If I do this:

import application.exceptions
try:
  do_something ()
except application.exceptions.CustomException:
  catch_me ()

it might work or not, depending on how the sub-module imported exceptions.py (which I do not know).

Question: Is there a way to circumvent this problem, i.e., a name for the exception that will always be understood regardless of inclusion path? If not, what would be best practices to avoid these name clashes?

Cheers,

Update

It is a Django app. some would be the name of the Django ‘project’, application the name of one Django app. My code with the try..except clause sits in another app, frontend, and lives there as a view in a file some/frontend/views.py.

The PYTHONPATH is clean, that is, from my project only /path/to/project is in the path. In the frontend/views.py I import the exceptions.py via import application.exceptions, which seems to work. (Now, in retrospective, I don’t know exactly, why it works…)

The exception is raised in the exceptions.py file itself.

Update 2

It might be interesting for some readers, that I finally found the place, where imports went wrong.

The sys.path didn’t show any suspect irregularities. My Django project lay in /var/www/django/project. I had installed the apps app1 and app2, but noted them in the settings.py as

INSTALLED_APPS = [
  'project.app1',
  'project.app2',
]

The additional project. was the culprit for messing up sys.modules. Rewriting the settings to

INSTALLED_APPS = [
  'app1',
  'app2',
]

solved the problem.

  • 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-11T22:14:42+00:00Added an answer on May 11, 2026 at 10:14 pm

    Why that would be a problem? exception would me matched based on class type and it would be same however it is imported e.g.

    import exceptions
    l=[]
    try:
        l[1]
    except exceptions.IndexError,e:
        print e
    
    try:
        l[1]
    except IndexError,e:
        print e
    

    both catch the same exception

    you can even assign it to a new name, though not recommended usually

    import os
    os.myerror = exceptions.IndexError
    try:
        l[1]
    except os.myerror,e:
        print e
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • 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 I presume you are using InstallUtil to install the service.… May 12, 2026 at 12:30 am
  • Editorial Team
    Editorial Team added an answer Disclaimer: I am a developer on this product so I… May 12, 2026 at 12:30 am
  • Editorial Team
    Editorial Team added an answer Not entirely sure that I understand you correctly. Is the… May 12, 2026 at 12:30 am

Related Questions

In this answer to another question , I was told that in scripts you
I am having a hard time figuring out why when the cfquery runs in
Update Well, as i was told by Stuart Charles and James Gregory, my model
Now that RC1 is out I need to decide once and for all whether

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.