Replace String in All Python Files in Terminal on Mac - DevPops-Inc/python GitHub Wiki
• Type cd < directory >
and press “return” key to change directory to where your Python files are located.
•
• Type ls
and press “return” key to list the contents of the directory.
•
• Type open < Python file >.py
and press “return” key to open a Python file in the default code editor.
•
• Find the string that you wish to replace.
•
• Type find . -name ‘*.py’ -print0 | xargs -0 sed -I “” ‘s/< old string >/< new string >/g’
(I used double quotes in the example because my strings contained single quotes) and press “return” key to replace a string in all Python files in the directory.
•
• You’ll see that the string has been replaced in your code editor.
•