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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:01:37+00:00 2026-05-13T18:01:37+00:00

I asked a similar question yesterday, but have acquired a really odd problem since

  • 0

I asked a similar question yesterday, but have acquired a really odd problem since then. With this directory structure:

app/
    models/
        __init__.py
        user.py
        other.py
    pages/
        __init__.py
        pages.py

The models/__init__.py file has this line:

__all__ = ['user', 'other']

and the pages/__init__.py has

__all__ = ['pages']

In pages.py, in order to use any of the classes in user.py or other.py, I have to have

from models import *
import models

at the top, and then I can declare a User class like this:

my_user = models.user.User()

If I exclude either of the import-ing statements at the top, I get errors like

"Class user has no attribute User"

Any help would be appreciated. I love Python, but I wish it’s import functionality worked more like PHP’s.

  • 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-13T18:01:37+00:00Added an answer on May 13, 2026 at 6:01 pm

    There are two options, depending on where you want to be explicit and how much you want available “by default” (which also means forced).

    In those __init__ files you could use:

    # models/__init__.py shown:
    import user, other                 # ambiguous relative import
    from . import user, other          # relative import
    from app.models import user, other # absolute import
    

    Or, where you would otherwise just have import models, use:

    from models import user, other
    # or:
    import models.user, models.other
    

    The latter form is more widely preferred.

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

Sidebar

Related Questions

I asked a similar question yesterday, but now I have a slight twist. Since
I asked a similar question like this yesterday but after waiting for ever I
This is similar to a question I asked yesterday but more specific to the
I asked a similar question about this previously, but I did not specify that
I have asked a similar question before, but I didn't have a firm grasp
Similar questions to this one have been asked but none seem to address my
I asked a similar question yesterday, but recognize that i need to rephase it
I asked a similar question yesterday that was specific to a technology, but now
I asked a pretty similar question a few days ago, but this one is
I've already asked similar question on this issue on stack overflow already, but I

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.