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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:29:41+00:00 2026-05-16T01:29:41+00:00

I have a module (tools.py) containing many classes. I’d like to extract these out

  • 0

I have a module (tools.py) containing many classes. I’d like to extract these out into its own “whyteboard.tools” package, each class being inside its own file.

However, I previously moved from having all my classes in one base directory to being in a package below the root of my project, and had issues with loading in pickled files that had been saved in the old format. (see: https://stackoverflow.com/questions/2121874). I had to monkey patch the sys.modules dict while loading the file and then delete it afterwards. nasty…

What’s the best way to do this move?

Is it best to also import each of my classes in the package’s __init__ otherwise I’d have to

from whyteboard.tools.pen import Pen 

instead of

from whyteboard.tools import Pen
  • 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-16T01:29:42+00:00Added an answer on May 16, 2026 at 1:29 am

    What’s the best way to do this move?

    First. Don’t. Class per file isn’t going to improve anything, so why bother?

    had issues with loading in pickled files that had been saved in the old format

    Correct. You must have issues loading files pickled in the old format because the class names have changed.

    Why change them if it causes problems?

    If you absolutely must change them, you can try something like this to convert. Saves monkey patching. Moves forward to your new architecture.

    import this.that.module 
    import pickle
    import os
    legacy_obj= pickle.load( someFile )
    os.rename( someFile, someFile+".bak")
    
    import this.that.module.class
    new_obj= this.that.module.class( legacy_obj )
    pickle.save( someFile )
    

    There’s a middle ground between 1900 lines in one file and 8+ files with 200+ lines each. A single class of 200+ lines indicates that you may have other design problems. You might want to tackle those first before creating 8 files of “1 class each”.

    Consider that a 200-line class may already be doing too much. You might want to decompose your classes to have more fine-grained responsibilities. Having done that you may find that you have a few modules — each with a few classes.

    You might want to decompose collections of related classes into reusable modules. A simplistic “class-per-file” approach may be a poor way to restructure this.

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

Sidebar

Related Questions

I have a Python module installed on my system and I'd like to be
I have a Perl module that I would like to use from Java. Is
I have a module in the parent directory of my script and I would
I have a module that sends an email to a specified email address but
i have a module (a single .py file, actually), with a class called HashedDir.
Background: I have a module which declares a number of instance methods module UsefulThings
So I have a module in flex in which I add a custom component.
Typically I create a plugin when I have a module that I know I'm
I have a C# module responsible for acquiring the list of network adapters that
I have a python module that makes use of a huge dictionary global variable,

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.