A simple guide on this extremely simple yet rare setup.
This was my question as well a few days back; when I decided to start CP again. One thing I noticed was the abundance of articles and blogs for setting up code editors for CP using C++ as main language; it is completely natural given quick pace, macros and short syntax of C++. But, the lack of resources to set up code editors with python really bugged me. I too wanted to create the same cool looking CP window with partition; and here it is; a simple guide on this extremely simple yet rare setup. Here we go…
Step 1: Install Python
Step 2: Install Sublime Text
Step 3: Install a good auto-complete engine
Step 4: From here, begins the most crucial part, i.e. looks, just kidding ;-)
before that, create three files as given below:
1. solution.py: The file for writing the code.
2. input.txt: The file where we will be giving the input.
3. output.txt: The file where the output will be displayed.
4. error.txt: The file where the error will be displayed.
Step 5: Changing the view : Open your sublime text, Now, perform the following steps:
Step 6: Opening all files that we created on each panel.
Simply move to the panel and press “Ctrl + O”, and select the files you want for each panel. After doing this the editor would look something like this:
Step 7: Setting up the template code; so that you need not to write same stdin and stdout everytime:
Select Tools > Developer > new snippet, and replace the existing code with the one given below:
<snippet> <content><![CDATA[ import sys sys.stdin = open("input.txt", "r") sys.stdout = open("output.txt", "w") sys.stderr = open("error.txt", "w") # your remaining code ]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger>dsa</tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <scope>source.python</scope> </snippet>
Let me explain above snippet a bit;
Inside the <content> tag we are going to place our default code, whose first 4 lines deals with setting up your standard input/output/error to a custom file(which we already created), below that you can put any sort of template code you want(you can see mine in picture above the code snippet).
Next, we have <tabTrigger>dsa</tabTrigger>, you can replace “dsa” with anything, your name/city/any other command, the aftermath of this is that, whenever you will open a new file, type “dsa” and hit Enter, it will automatically put your template on your empty editor. Isn’t that convenient?
Step 7: Finishing up
Write your code on python file we created, and put your input onto input.txt file, to build the script, press: “Ctrl+b”, you will see your output reflected in output.txt file, which is open in 2nd panel on right view/column.
And we are done, I know a lot could be done apart from this; like creating our own build; but, I am aiming for a simple and easy to understand setup, and hopefully that is what I delivered. Do let me know in comments if you want to see the custom-build step as well; though I have to research on that a bit ;-).
Finally, All the best for your learning and Happy coding!!
For custom build, and better experience follow the simple step mentioned in second part of this article.