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

The Archive Base Latest Questions

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

This has probably been asked before but I couldn’t find the answer to my

  • 0

This has probably been asked before but I couldn’t find the answer to my specific question (fairly general…)

Here is an example of my question. Say my package is called ‘school’, and I have a class called ‘book’ which will have .py files along side it containing the meat of its methods. I’m not sure how to organize it all so that import statements don’t look strange.

How do I organize files?

/school/
        pencil/
        book/
             __init__.py
             read.py
             burn.py
             book.py

I want to be able to do something like this, since it makes the most sense:

from school import Book
b = Book(name="The Bible")
b.read()

But from the file structure above, I would have to do:

from school.book import Book
b = Book(....etc

OR

from school import book
b = book.Book(...etc

These are awkward/repetitive…what am I missing 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. Editorial Team
    Editorial Team
    2026-05-24T07:54:06+00:00Added an answer on May 24, 2026 at 7:54 am

    You’re confusing packages with classes I think. Personally, I’d put every class definition and all functions that were directly related to that class in the same .py file. For instance, reading is not an object, so I would put that as a function under the Book class, not it’s own .py file. So, the structure would look something like this.

    /school/
        pencil.py
        book.py
    

    Inside book.py, you’d have something like this

    class Book():
        def __init__(self,name,author,isbn,your_variable_here):
            #Your init method
    
        def read(self,kid):
            return "{0} is reading {1}.".format(kid,self.name)
    
        def burn(self,library,lighter):
            library.remove(self)
            lighter.light(self)
            return "Preparing to burn people."
    

    Then, your imports look like this.

    from school import book
        b = book.Book("The Art of War","Sun Tzu",'999342052X','Books rock!')
        b.read(ike) #This assumes ike is an object, probably of the class Student, defined and imported from elsewhere
        b.burn(library,lighter) #Once more, I'm assuming these are objects for which you've imported the definition and defined them earlier.
    

    This advantage of this system is it more closely models reality. Rather than a bunch of functions bundled by a file structure (which, as you noted, can get convoluted), you’ve got the grouped by classes into logical groups and constructs. However, I’d argue that Student should have the read function and library should have the checkout function, leaving books with only the burn function. But that’s because books don’t read, people do. And books don’t check out, libraries do. That’s a question of how you want to organize it.

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

Sidebar

Related Questions

This is probably a question that has been asked before, but I couldn't find
This probably has probably been asked before, but I couldn't find anything relevant. Would
This has probably been asked before, but I couldn't find it. Is there a
This has probably been asked before but I can't seem to find the answer.
This has probably been asked before, but I can't find a good way of
This has probably been asked before on SO, but I was unable to find
I know this has probably been asked before, but I can't find it with
This has probably been asked before but I can't find any relevant post using
This has probably been asked before but I can't find it anywhere. I have
I know this has probably been asked before but I can't seem to find

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.