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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:14:26+00:00 2026-06-13T21:14:26+00:00

I wrote some code in python as a class, but now I’m trying to

  • 0

I wrote some code in python as a class, but now I’m trying to prepare it for distribution as a package and I was having some trouble with figuring out how the different pieces should fit together.

So, as I originally wrote the code I had a class with a few functions in it, including an __init__ function. I’ve now split each of these functions into its own file named with the function name, but I’m unsure where to put the init function, since it takes arguments. An example is below.

Original format:

class className(object):

    def __init__(self, arg1, arg2):
         self.arg1 = arg1
         self.arg2 = arg2

    def func1(self):

    def func2(self, arg3):

With a usage of:

import name

a = name.className(arg1, arg2)
a.func1()
a.func2(arg3)

Now the file tree is:

Name/
    /className
        __init__.py
        func1.py
        func2.py

And on to include the other functions. I would like to keep the same basic usage pattern as the original.

Now, the question I have is where that __init__ function should go? Inside the __init__.py file? Somewhere else? The other issue is I wanted to put some imports in the __init__.py file; I know they should go in the __init__.py file, but I don’t know how they relate to the __init__ function. Any help is appreciated.

  • 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-06-13T21:14:27+00:00Added an answer on June 13, 2026 at 9:14 pm

    You can’t split a class across multiple files. A package should contain multiple modules, which are files containing code (complete classes, functions, etc…).

    The __init__.py file is run when the package is imported (although it’s rare it is used to actually execute much code) and tells Python the directory is a package, it’s not the constructor for a class.

    A package (folder) should be a collection of packages and modules, while a module (file) will be a collection of code.

    An example of a normal hierarchy:

    - somepackage (Folder)
        - __init__.py (File)
        - somemodule.py (File)
            - SomeClass (Code)
            - some_function (Code)
    

    As a final note, I say you can’t split a class across multiple files – technically you could do this by monkey patching functions into the class or some other such weirdness, but you’d never want to as it would obscure your code a lot.

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

Sidebar

Related Questions

I'm trying to access some C code via Python using ctypes, so I wrote
I wrote some code for the ising model in python (2d). Everything looks seems
I have some python code that I wrote to convert a python list into
I'm trying to write some Python code that will establish an invisible relay between
I wrote some code to read a file in my Java Servlet class. (I'm
I have started working with the google Python class but I am getting some
I'm cleaning some of the Python code I wrote when I was...not as knowledgeable.
I am trying to write some python code using tornado. Here is my code.
I wrote some code in VHDL that is expected to look at a rotory
I wrote some code that activity starts a service to get some text from

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.