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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:40:36+00:00 2026-06-01T09:40:36+00:00

Is it possible to add properties and special methods to modules? I want to

  • 0

Is it possible to add properties and special methods to modules? I want to define a module such that importing it acts like a class instance, and the body acts as a class definition. Essentially, it’s to avoid ugly syntax like this:

import game
if game.Game().paused:
    print("The game is paused")

E.g. the game module would look like this:

_Speed = 1

@property
def paused():
    return _Speed == 0

And the file using it:

import game
if game.paused:
    print("The game is paused")

Also, is it possible to define special methods (such as __call__)?

To be clear, I do not differentiate between class/instance methods, since I’m using game.Game as a singleton/borg class.

I have tested using @property and defining __bool__, but neither acts as I hoped.

Edit (information on why I want to use a property):

I have a property game.speed, a function game.paused() and a function game.pause(bool). Essentially, I have a temporary variable used to store the game speed when the game is paused. There is a private speed variable that is set to zero when the game is paused. I never want the user to see the speed as being zero, and be able to modify the speed while the game is paused, so that when the game is resumed, it uses the new speed.

  • 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-01T09:40:37+00:00Added an answer on June 1, 2026 at 9:40 am

    Python doesn’t care that what’s in sys.modules is actually a module. So you can just:

    # game.py
    class Game(object):
        pass
    
    import sys
    sys.modules["game"] = Game()
    

    Now other modules that import game will get the Game instance, not the original module.

    I’m not sure I recommend it, but it’ll do what you want.

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

Sidebar

Related Questions

Would it be possible to add a new operator to the String class that
Is it possible to modify a .properties file in Tomcat, that is to add
I want to know if it is possible to add properties to the event
I know it's possible to add methods and properties to discriminated unions, but can
Is it possible to add properties to my model that dont exist in the
Is it possible to add model state error message during updating properties using TryUpdateModel?
I'm looking for a way to add properties to my already defined class at
Is it possible to add something like Modernizr into your own plugin? I'd like
Is it possible to add a class as a solution item and use it
I know that in JavaScript you can add new properties to an instance of

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.