Python Forum
looking for code that substitues parts of python code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
looking for code that substitues parts of python code
#1
i am looking for code, preferably organized as a function, that given a big string containing valid Python code, can substitute one string for another, and not make the change inside comments, or inside string literals of any type, anywhere. this could be used to change variable names and function/method calls in the given code string. it must support byte literals in the substituted string of code, but supporting bytes in the call arguments is not required although is otherwise a plus.

a nice alternative is code that can take a string of valid Python code and generate parts representing pieces of the code as it would be parsed, each yielded as a 2-tuple or 2-list with a type code and the string part. all these strings, joined together, will be the same as the original code given to it. then i would be trivial to do things like substitute all variable names not in literals or comments.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can you recommend me a vps that will run api python code? SuchUmami 2 1,026 Aug-16-2023, 02:21 PM
Last Post: snippsat
  Incredible stability of Python code Gribouillis 1 702 Jun-25-2023, 10:14 PM
Last Post: Larz60+
  Convert Python code to MATLAB code bitoded 4 4,976 Dec-30-2022, 02:06 AM
Last Post: Larz60+
  shortening Python code Skaperen 12 2,478 Oct-23-2022, 10:54 PM
Last Post: Skaperen
  Accessing Python code & SQL datbase from other pc's Extra 1 1,100 Jun-24-2022, 11:30 PM
Last Post: Larz60+
  filtering python code the interpreter reads Skaperen 0 1,176 Feb-02-2022, 08:29 PM
Last Post: Skaperen
  running produced python code Skaperen 6 1,927 Dec-25-2021, 05:52 PM
Last Post: Skaperen
  parsin python code Skaperen 5 2,755 Feb-25-2021, 07:50 PM
Last Post: Skaperen
  Creating Python scripts in Visual Studio Code Sanjish 4 2,618 Dec-22-2020, 12:32 PM
Last Post: snippsat
  parsing Python-like code Skaperen 4 2,416 Nov-06-2020, 12:17 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020