Skip to content

Instantly share code, notes, and snippets.

@SpiffGreen
Created April 24, 2025 13:43
Show Gist options
  • Save SpiffGreen/d24804b6284ff464aae258e86681c4b9 to your computer and use it in GitHub Desktop.
Save SpiffGreen/d24804b6284ff464aae258e86681c4b9 to your computer and use it in GitHub Desktop.
Code to turn python with braces to proper python
import sys
# Coupled with this extension
# https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave
# And VS Code setting after extension install
# "emeraldwalk.runonsave": {
# "commands": [
# {
# "match": ".*\\.py$",
# "cmd": "python3 clean_braces.py ${file}"
# }
# ]
# }
path = sys.argv[1]
with open(path, 'r+') as f:
code = f.read()
# Remove standalone curly braces
code = code.replace('{', ':').replace('}', '')
f.seek(0)
f.write(code)
f.truncate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment