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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:15:21+00:00 2026-06-15T11:15:21+00:00

I feel this is a very simple question but I can’t find to seem

  • 0

I feel this is a very simple question but I can’t find to seem a proper answer. Basically I have a list of functions call from a class named simulation:

simulation.addGroup("teapotarmy")
simulation.populateGroup(20)
simulation.addNode("input",INPUT)
simulation.addNode("output",OUTPUT);
simulation.connectNodes("input","output");
simulation.manipOutputNode("output", "group.xvel");
simulation.manipInputNode("input", 1, 0.05);

Is there a way to call those functions without having to repeat the class name everytime? Something along the line of:

(thethingIwant) simulation:
    addGroup("teapotarmy")
    populateGroup(20)
    addNode("input",INPUT)
    ...

I have done this in other programming languages but I haven’t figured out the syntax in Python. I have a faint memory of it having something to do with the ‘with’ statement…?
Thanks in advance.

Leon

  • 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-15T11:15:23+00:00Added an answer on June 15, 2026 at 11:15 am

    Simply, no. There is no (good, see my comment at the end) way to do this. The best you could do is assign it to another, shorter name:

    s = simulation
    s.addGroup("teapotarmy")
    ...
    

    Which isn’t too bad, although I’d argue the normal method is the one that is more readable.

    As an extra, it’s not strictly true that you can’t do this. You could assign all of the methods of simulation to the local namespace programatically, however, this would be pretty confusing to follow, and I’d advise against it.

    Example:

    from contextlib import contextmanager
    import inspect
    
    class some_class:
        def test(self):
            print("test!")
    
    @contextmanager
    def map_to_local(inst, locals):
        methods = inspect.getmembers(inst, inspect.ismethod)
        for name, method in methods:
            locals[name] = method
        yield
        for name, method in methods:
            del locals[name]
    
    inst = some_class()
    with map_to_local(inst, locals()):
        test()
    

    Note this is pretty fragile – you would have to be careful and do stuff like checking you are not overwriting values, checking values haven’t been deleted before the context manager exits, etc… It’s also pretty unclear what is going on.

    tl;dr: Yes, it’s possible, no, you shouldn’t do it. Your current code is fine and clear.

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

Sidebar

Related Questions

I feel very very very silly posting this, but I can't find the answer.
I feel like the answer to this question is probably very simple, but I'm
I feel like this is a rather simple question, but I can't seem to
I'm sure this is a very stupid question but I can't find the answer,
This is a very simple question and I feel stupid for asking it, but
I feel very noobish asking this, but I can't seem to figure it out...
I feel like the answer to this question is really simple, but I really
I feel like this is a very noob question.. but I just can't get
I feel that this is a very simple question, but I'm new to Python,
I feel as if this should be very simple, but it's behaving strangely. I

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.