I would like to import all methods from a module with altered names.
For instance, instead of
from module import repetitive_methodA as methodA, \
repetitive_Class1 as Class1, \
repetitive_instance4 as instance4
I'd prefer something along the lines of
from module import * as *-without-"repetitive_"
this is a rephrasing of this clumsy unanswered question, I have not been able to find a solution or similar questions yet.
You can do it this way:
Edit in response to the comment "how is this answer intended to be used?"
Suppose
module
looks like this:Then after running the rename loop, this code:
produces this output:
What I would do, creating a work-around...
Including you have a file named
some_file.py
in the current directory, which is composed of...When you import something, you create an object on which you call methods. These methods are the classes, variables, functions of your file.
In order to get what you want, I thought It'd be a great idea to just add a new object, containing the original functions you wanted to rename. The function
redirect_function()
takes an object as first parameter, and will iterate through the methods (in short, which are the functions of your file) of this object : it will, then, create another object which will contain the pointer of the function you wanted to rename at first.tl;dr : this function will create another object which contains the original function, but the original name of the function will also remain.
See example below. :)
This outputs...