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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:24:57+00:00 2026-05-11T05:24:57+00:00

I am confused how directory name, file name and class name all work together.

  • 0

I am confused how directory name, file name and class name all work together.

This is what I have at the moment

  app.py   database/      client.py      staff.py      order.py 

Inside client.py I have a single class called client, which acts as the database model (MVC). The same with my other files: staff.py has a class called staff, order.py has order.

Then in app.py I do:

  from database import client as model   c = model.client() 

And then I get confused. In an ideal world this is what I want to do:

  1. Keep my database model classes in separate files in their own directory.

  2. Use them like this:

  c = model.client()   o = model.order()   s = model.staff() 

The only way I can see to do this is to put all my classes in a single file called model.py and save this at the root.

I’m sure I am missing something very basic here.

  • 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. 2026-05-11T05:24:58+00:00Added an answer on May 11, 2026 at 5:24 am

    Python has two basic ways of importing content. Modules and Packages.


    A module is simply a python file on the include path: order.py

    If order.py defines a class named foo, then access to that class could be had by:

    import order o = order.foo() 

    In order to use the syntax from the orignial question, you would need to ensure that your model.py file has the following attributes: [client, staff, order]

    However, that typically means placing them in a single file. Which is what you are trying to avoid.


    A package is a directory with an __init__.py inside of it. The init.py initializes the package (ie. it is run on first import), and you can have either modules or sub-packages within that directory.

    model     __init__.py     client.py     staff.py     order.py 

    That way, to access any of the sub modules, you would simply say:

    import model.client 

    However, that is simply importing the module. It is not importing any of the attributes of the module. So in order to access a class inside the module, you would need to specify it:

    import model.client o = model.client.clientclass()    

    This is a bit tedious, but very well organized.


    Best of both (where performance isn’t a big deal):

    If you type the following code in __init__.py:

    from .client import clientclass as client from .staff import staffclass as staff from .order import orderclass as order 

    Then you have auto-loaded all of your classes, and they can be accessed as:

    import model c = model.client() s = model.staff() o = model.order() 

    In the end, it may be more simple to stick with the non-magical way to do it:

    import model.client o = model.client.clientclass()    

    –Gahooa

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

Sidebar

Related Questions

I'm confused with file moving under python. Under windows commandline, if i have directory
Totally confused by this one... We have a WAMPServer installation set up, running a
I'm currently using commons-net library for FTP client in my app. I have to
Okay, I am confused! I have a directory with ~40,000 files, and I created
I'm new to python, and confused by certain behavior. I have a directory called
I am really confused i have a directory structure as follows. /foo/bar/project/ under project
Very confused here, trying out the yuicompressor on a simple javascript file. My js
Bit confused here, I have an on-demand instance but do I get charged even
Totally confused here. I have a PARENT UIViewController that needs to pass an NSMutableArray
I have an app that recurses through a drive and outputs files that have

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.