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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:35:43+00:00 2026-06-01T13:35:43+00:00

So I have a common module which contains processing functions for numbers and types

  • 0

So I have a common module which contains processing functions for numbers and types of data I am using. I want to be able to include it like from common import common (or better yet just import common) and use functions like common.howLongAgo(unixTimeStamp)

What is required to do this in my common module?. Common is a module consisting of a class ‘common’.

  • 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-01T13:35:45+00:00Added an answer on June 1, 2026 at 1:35 pm

    Ways of exposing methods in a python module:

    module foo.py:

    def module_method():
        return "I am a module method"
    
    class ModClass:
         @staticmethod
         def static_method():
             # the static method gets passed nothing
             return "I am a static method"
         @classmethod
         def class_method(cls):
             # the class method gets passed the class (in this case ModCLass)
             return "I am a class method"
         def instance_method(self):
             # An instance method gets passed the instance of ModClass
             return "I am an instance method"
    

    now, importing:

    >>> import foo
    >>> foo.module_method()
    'I am a module method'
    >>> foo.ModClass.static_method()
    'I am a static method'
    >>> foo.ModClass.class_method()
    'I am a class method'
    >>> instance = ModClass()
    >>> instance.instance_method()
    'I am an instance method'
    

    If you want to make class method more useful, import the class directly:

    >>> from foo import ModClass
    >>> ModClass.class_method()
    'I am a class method'
    

    You can also import ... as ... to make it more readable:

    >>> from foo import ModClass as Foo
    >>> Foo.class_method()
    'I am a class method'
    

    Which ones you should use is somewhat a matter of taste. My personal rule of thumb is:

    • Simple utility functions that generally act on things like collections, or perform some computation or fetch some resource should be module methods
    • Functions related to a class but that do not require either a class or an instance should be static methods
    • Functions that are related to a class, and will need the class for comparison, or to access class variable should be class methods.
    • Functions that will act on an instance should be instance method.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a module which contains a lot of functions (more than 25). I
I have a file Tools.ml which contains some common utility functions I write myself.
I have a Perl script which uses a not-so-common module, and I want it
I have a common resource, which I want 1 and only 1 instance of
I have a Perl script (standalone program) which contains some subs I'd like to
I have the following structure: common-module Contains the common module related , services and
I want to create templates for base new reports on to have common designs.
We have several common libs. Ideally we want them all to use the latest
I have a common script which Im including in my PHPcron files and the
I have type classes, for all of which I would like to have some

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.