Skip to content

Instantly share code, notes, and snippets.

@sjsakib
Created September 9, 2017 04:21
Show Gist options
  • Save sjsakib/19f2e3e964c50793113951536724c485 to your computer and use it in GitHub Desktop.
Save sjsakib/19f2e3e964c50793113951536724c485 to your computer and use it in GitHub Desktop.
Toggles input with file line in sublime text. Useful for competative programming
import sublime_plugin
class TogglePythonFileInputCommand(sublime_plugin.TextCommand):
def run(self, edit):
reg1 = self.view.find(r"# sys\.stdin = open\('in', 'r'\)", 0)
reg2 = self.view.find(r"# import sys", 0)
if not reg1.empty():
self.view.replace(edit, reg1, "sys.stdin = open('in', 'r')")
else:
reg1 = self.view.find(r"sys\.stdin = open\('in', 'r'\)", 0)
if not reg1.empty():
self.view.replace(edit, reg1, "# sys.stdin = open('in', 'r')")
if not reg2.empty():
self.view.replace(edit, reg2, "import sys")
else:
reg2 = self.view.find(r'import sys', 0)
if not reg2.empty():
self.view.replace(edit, reg2, "# import sys")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment