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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:06:56+00:00 2026-05-13T09:06:56+00:00

EDIT: OK, I managed to isolate the bug and the exact, complete code to

  • 0

EDIT:
OK, I managed to isolate the bug and the exact, complete code to to reproduce it. But it appears either something that’s by design, or a bug in python.

Create two sibling packages: admin & General, each with it’s own __init__.py, of course.
In the package admin put the file ‘test.py’ with the following code:

from General.test02 import run
import RunStoppedException
try:
    run()
except RunStoppedException.RunStoppedException,e:
    print 'right'
except Exception,e:
    print 'this is what i got: %s'%type(e)

and also in admin put the file ‘RunStoppedException.py’ with the following code:

class RunStoppedException(Exception):
    def __init__(self):
        Exception.__init__(self)

In the package General put the file test02.py with the code:

import admin.RunStoppedException
def run():
    raise admin.RunStoppedException.RunStoppedException()

the printout:

this is what i got: <class 'admin.RunStoppedException.RunStoppedException'>

When it should’ve been right. This only happens when one file sits in the same dir as the exception, so they import it differently.

Is this by design, or a bug of python?

I am using python2.6, running it under eclipse+pydev

  • 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-13T09:06:57+00:00Added an answer on May 13, 2026 at 9:06 am
    import admin.RunStoppedException
    

    This is an ambiguous relative import. Do you mean RunStoppedException from the admin top-level module? Or from mypackage.admin when you’re in a package? If your current working directory (which is added to the module search path) happens to be inside the package, it could be either, depending on whether Python knows it’s inside a package, which depends on how you’re running the script.

    If you’ve got both import admin.RunStoppedException and import RunStoppedException in different modules, that could very well import two copies of the same module: a top-level RunStoppedException and a submodule admin.RunStoppedException of the package admin, resulting in two instances of the exception, and the subsequent mismatch in except.

    So don’t use implicit relative imports. They are in any case going away (see PEP328). Always spell out the full module name, eg. import mypackage.admin.RunStoppedException. However avoid using the same identifier for your module name and your class name as this is terribly confusing. Note that Python will allow you to say:

    except RunStoppedException:
    

    where that identifier is referring to a module and not a subclass of Exception. This is for historical reasons and may also go away, but for the meantime it can hide bugs. A common pattern would be to use mypackage.exceptions to hold many exceptions. One-class-per-file is a Java habit that is frowned on in Python.

    It’s also a good idea generally try to keep the importing of module contents (like classes) down as much as possible. If something changes the copy of RunStoppedException inside the module, you’ll now have different copies in different scripts. Though classes mostly don’t change, module-level variables may, and monkey-patching and reloading become much harder when you’re taking stuff outside of its owner module.

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

Sidebar

Ask A Question

Stats

  • Questions 466k
  • Answers 466k
  • 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 If you're able to use XSLT 2.0 I would suggest… May 16, 2026 at 1:36 am
  • Editorial Team
    Editorial Team added an answer I have the html here with few changes.. $(function(){ $('#mytab… May 16, 2026 at 1:36 am
  • Editorial Team
    Editorial Team added an answer You cannot encrypt the entire <system.serviceModel> - it's a configuration… May 16, 2026 at 1:36 am

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.