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

The Archive Base Latest Questions

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

I have been trying to fix this for a bit, and I must be

  • 0

I have been trying to fix this for a bit, and I must be missing something basic here (forgive me, I am relatively new to Python development):

I have a package structure like this:

base
|
 -->util
    __init__.py
    Class1.py
    Class2.py
__init__.py
Main.py

My classes are fairly benign:

class Class1(object):

    def __init__(self):

    # some methods...


class Class2(object):

    def __init__(self):

    # more methods...

In the Main.py, I have:

import utils

if __name__ == '__main__':
    c1 = utils.Class1()
    c2 = utils.Class2()

My PYTHONPATH is setup to include src, src\base, and src\base\utils. But, Python gives me this error when trying to run Main.py:

AttributeError: 'module' object has no attribute 'Class1'

Has someone encountered this, and do you know how to fix it? Thanks!

  • 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-30T16:10:34+00:00Added an answer on May 30, 2026 at 4:10 pm

    This is a little different than Java. In java each file is usually a class, in python, each file is a module. Given the scenario you describe here, you would do:

    import utils.Class1
    import utils.Class2
    
    if __name__ == '__main__':
        c1 = utils.Class1.Class1()
        c2 = utils.Class2.Class2()
    

    You could do a number of things here. For example, you could have a module called “resources” like this:

    base ->
        utils ->
            resources.py
    

    which contains both Class1 and Class2. Then you could do something like:

    import utils.resources
    
    
    c1 = utils.resources.Class1()
    

    etc. But the key is that classes != files in python

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

Sidebar

Related Questions

Have been trying to fix this problem I have here. Basically I have a
Have been trying to fix this for the past hour. Here goes: <script type=text/javascript>
So, I have been trying to fix this for about two months. It all
I really need some help with this as I have been trying to fix
I have been trying to fix this problem for hours. My app keeps crashing
I have been trying desperately to fix this issue where my ListView items are
I have been trying to fix this script for more than an hour and
Ok so I have been trying to fix this for days, and I'm not
I have been trying to fix this for a while but I have had
I have been trying to fix this issue for weeks but I'm at the

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.