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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:13:40+00:00 2026-06-09T20:13:40+00:00

I refactor my old code and want to change the names of functions in

  • 0

I refactor my old code and want to change the names of functions in accordance with pep8. But I want to maintain backward compatibility with old parts of system (a complete refactoring of the project is impossible because function names is a part of the API and some users use the old client code).

Simple example, old code:

def helloFunc(name):
    print 'hello %s' % name

New:

def hello_func(name):
    print 'hello %s' % name

But both functions should work:

>>hello_func('Alex')
>>'hello Alex'
>>helloFunc('Alf')
>>'hello Alf'

I’m thinking about:

def helloFunc(name):
    hello_func(name)

, but I do not like it (in project about 50 functions, and it will look a messy, I think).

What is the best way to do it(excluding duplication ofcource)? Is it possible the creation of a some universal decorator?

Thanks.

  • 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-09T20:13:42+00:00Added an answer on June 9, 2026 at 8:13 pm

    I think that for the time being, the easiest thing is to just create a new reference to the old function object:

    def helloFunc():
        pass
    
    hello_func = helloFunc
    

    Of course, it would probably be more slightly more clean if you changed the name of the actual function to hello_func and then created the alias as:

    helloFunc = hello_func
    

    This is still a little messy because it clutters your module namespace unnecessarily. To get around that, you could also have a submodule that provides these “aliases”. Then, for your users, it would be as simple as changing import module to import module.submodule as module, but you don’t clutter your module namespace.

    You could probably even use inspect to do something like this automagically (untested):

    import inspect
    import re
    def underscore_to_camel(modinput,modadd):
        """
           Find all functions in modinput and add them to modadd.  
           In modadd, all the functions will be converted from name_with_underscore
           to camelCase
        """
        functions = inspect.getmembers(modinput,inspect.isfunction)
        for f in functions:
            camel_name = re.sub(r'_.',lambda x: x.group()[1].upper(),f.__name__)
            setattr(modadd,camel_name,f)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going to refactor certain parts in a huge code base (18000+ Java classes).
In order to refactor my MATLAB code, I thought I'd pass around functions as
actually i refactor some portion of code. what i want to do is to
I've a old C/C++ class that i want to refactor and access from .net
I feel the need to refactor my old CF5 based code into CFC's. We
I have a wonderful opportunity to refactor out old and smelly code into a
I am attempting to refactor several old pieces of code... I have refactored the
I'd like to refactor some old C code of mine, and I was curious
I want to refactor an emun in two new enums, but I don't like
I have to refactor and maintain a bunch of horrible similar looking Java classes.

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.