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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:38:36+00:00 2026-05-31T04:38:36+00:00

Using new style classes (I’m in python 3.2) is there a way to split

  • 0

Using “new” style classes (I’m in python 3.2) is there a way to split a class over multiple files? I’ve got a large class (which really should be a single class from an object-oriented design perspective, considering coupling, etc, but it’d be nice to split over a few files just for ease of editing the class.

  • 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-31T04:38:38+00:00Added an answer on May 31, 2026 at 4:38 am

    If your problem really is just working with a large class in an editor, the first solution I’d actually look for is a better way to break down the problem. The second solution would be a better editor, preferably one with code folding.

    That said, there are a couple of ways you might break up a class into multiple files. Python lets you use a folder as a module by putting an __init__.py in it, which can then import things from other files. We’ll use this capability in each solution. Make a folder called, say, bigclass first.

    1. In the folder put the various .py files that will eventually comprise your class. Each should contain functions and variable definitions for the eventual class, not classes. In __init__.py in the same folder write the following to join them all together.

      class Bigclass(object):
      
          from classdef1 import foo, bar, baz, quux
          from classdef2 import thing1, thing2
          from classdef3 import magic, moremagic
          # unfortunately, "from classdefn import *" is an error or warning
      
          num = 42   # add more members here if you like
      

      This has the advantage that you end up with a single class derived directly from object, which will look nice in your inheritance graphs.

    2. You could use multiple inheritance to combine the various parts of your class. In your individual modules you would write a class definition for Bigclass with parts of the class. Then in your __init__.py write:

      import classdef1, classdef2, classdef3
      
      class Bigclass(classdef1.Bigclass, classdef2.Bigclass, classdef3.Bigclass):
          num = 42   # add more members if desired
      
    3. If the multiple inheritance becomes an issue, you can use single inheritance: just have each class inherit from another one in chain fashion. Assuming you don’t define anything in more than one class, the order doesn’t matter. For example, classdef2.py would be like:

      import classdef1
      class Bigclass(classdef1.Bigclass):
           # more member defs here
      

      classdef3 would import Bigclass from classdef2 and add to it, and so on. Your __init__.py would just import the last one:

      from classdef42 import Bigclass
      

    I’d generally prefer #1 because it’s more explicit about what members you’re importing from which files but any of these solutions could work for you.

    To use the class in any of these scenarios you can just import it, using the folder name as the module name: from bigclass import Bigclass

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

Sidebar

Related Questions

I'm using new style classes in Python 2.6 and am having trouble with __getattr__
Given a custom, new-style python class instance, what is a good way to hash
Newbie question. Pylons 1 + SQLA using declarative style. New to Python. I have
I'm parsing an email using the below style message = Mail.new(body) #where body is
I am creating a new Widget using the same structure/style as the other Swing
I've been using heavily Prototype's way of defining classes and subclasses: // properties are
I have recently stated trying to use the newer style of classes in Python
I am concerned with using CSS classes that are defined in style sheets with
Is there a way to wipe out all CSS rules once style sheets have
I'm using the new RichTextBox control in SL4Beta and want to create styles for

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.