2

I'm looking for some way to do this with Python itself, not using an IDE.

Example:

def upper(string):
    return string.upper()

def reverse_string(string):
    return string[::-1]

string = 'abc'
reverse_upper = reverse_string(upper(string))

Converts to:

string = 'abc'
reverse_upper = string.upper()[::-1]

I'm considering making a solution that works recursively with inspect.getsourcelines. Is there any other function or library that will get me further along?

2
  • 4
    This is called inline expansion or "inlining". Why do you want to do it in Python? Commented Feb 18, 2020 at 17:28
  • 1
    @kaya3 It's a portion of a code rewriting program, not something I want to do on one codebase. I knew the "inline" term, but not "inline expansion". I think that's going to get me in the right direction. Thank you. Commented Feb 18, 2020 at 17:39

1 Answer 1

2

This comment from @kaya3 got me here.

There are two repos that do this that I can use as starting points: inliner and atinline. Neither are maintained, but I can use them for reference.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.