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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:20:54+00:00 2026-05-13T07:20:54+00:00

Basically I have a subpackage with the same name as a standard library package

  • 0

Basically I have a subpackage with the same name as a standard library package (“logging”) and I’d like it to be able to absolute-import the standard one no matter how I run it, but this fails when I’m in the parent package.

It really looks like either a bug, or an undocumented behaviour of the new “absolute import” support (new as of Python 2.5). Tried with 2.5 and 2.6.

Package layout:

foo/
    __init__.py
    logging/
        __init__.py

In foo/__init__.py we import our own logging subpackage:

from __future__ import absolute_import
from . import logging as rel_logging
print 'top, relative:', rel_logging

In foo/logging/__init__.py we want to import the stdlib logging package:

from __future__ import absolute_import
print 'sub, name:', __name__

import logging as abs_logging
print 'sub, absolute:', abs_logging

Note: The folder containing foo is in sys.path.


When imported from outside/above foo, the output is as expected:

c:\> python -c "import foo"
sub, name: foo.logging
sub, absolute: <module 'logging' from 'c:\python26\lib\logging\__init__.pyc'>
top, relative: <module 'foo.logging' from 'foo\logging\__init__.pyc'>

So the absolute import in the subpackage finds the stdlib package as desired.

But when we’re inside the foo folder, it behaves differently:

c:\foo>\python25\python -c "import foo"
sub, name: foo.logging
sub, name: logging
sub, absolute: <module 'logging' from 'logging\__init__.pyc'>
sub, absolute: <module 'logging' from 'logging\__init__.pyc'>
top, relative: <module 'foo.logging' from 'c:\foo\logging\__init__.pyc'>

The double output for “sub, name” shows that my own subpackage called “logging” is importing itself a second time, and it does not find the stdlib “logging” package even though “absolute_import” is enabled.

The use case is that I’d like to be able to work with, test, etc, this package regardless of what the current directory is. Changing the name from “logging” to something else would be a workaround, but not a desirable one, and in any case this behaviour doesn’t seem to fit with the description of how absolute imports should work.

Any ideas what is going on, whether this is a bug (mine or Python’s), or whether this behaviour is in fact implied by some documentation?

Edit: the answer by gahooa shows clearly what the problem is. A crude work-around that proves that’s it is shown here:

c:\foo>python -c "import sys; del sys.path[0]; import foo"
sub, name: foo.logging
sub, absolute: <module 'logging' from 'c:\python26\lib\logging\__init__.pyc'>
top, relative: <module 'foo.logging' from 'c:\foo\logging\__init__.pyc'>
  • 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-13T07:20:54+00:00Added an answer on May 13, 2026 at 7:20 am

    sys.path[0] is by default '', which means “current directory”. So if you are sitting in a directory with logging in it, that will be chosen first.

    I ran into this recently, until I realized that I was actually sitting in that directory and that sys.path was picking up my current directory FIRST, before looking in the standard library.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use sets to get the difference between the lists: >>>… May 13, 2026 at 6:28 pm
  • Editorial Team
    Editorial Team added an answer Locally they use SSDP to find peers that are on… May 13, 2026 at 6:28 pm
  • Editorial Team
    Editorial Team added an answer You can use this jQuery plugin for lazy loading images.… May 13, 2026 at 6:28 pm

Related Questions

So right now we have a lot of python scripts and we are trying
Basically I have a bunch of unmanaged VC++ static libraries. And the VC++ GUI
Basically I have a website. I have a properly setup sitemap so I assume
Basically I have a small template that looks like: <xsl:template name=templt> <xsl:param name=filter />
Basically I have a mysql query something like the following: mysql_query(SELECT n.title, v.value FROM

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.