Heyy guys, I hope you are doing great. Today I’ll be showing you a trick that can make your life easier as a python programmer. If you have been using sublime text like me, you would have realized by now that sublime text does not have an interactive shell to take input for your python programs. I absolutely love sublime text and I use it as my default IDE for Python. It is a great software to have in your computer because it supports a lot of languages like Python, Java, JavaScript, C++, C etc. Also it is super-fast in its execution, so if you have a low-end PC this will be IDEal for you (Get it??...because it is I...never mind). Also it is widely used and recognized by top developers and companies in the industry.

Having all these advantages sublime text 3 is not all good, because of its shell. If you use sublime text, you know the struggle of creating a super cool program that takes input from the user on various accounts, but sublime text just wouldn’t allow it, so you have to open the terminal and execute your python file from there. Today the struggle ends! I have got a solution to this problem. That is right, we will make sublime text 3 all good.

INSTALLING SUBLIMEREPL:

In order to make our programs interactive in sublime text, we have to install something called SublimeREPL. It is an official add-on from the creators of Sublime Text. You can install it from within your sublime text program. But first you have to install something called Package Control. You can do this by following these steps:

  1. Open your sublime text 3 program


  1. Press Ctrl + Shift + P or go to ‘Tools and select ‘Command Palette….’


  1. Type in ‘Package Control’ in the search bar

  2. Select ‘Install Package Control’ and wait for it to install (Make sure you are connected to the internet)

Package Control allows you to install various themes and other add-ons to your sublime text program. Now since it is done let us move on to installing SublimeREPL:

  1. Open your sublime text 3 program again

  2. Press Ctrl + Shift + P or go to ‘Tools and select ‘Command Palette….’ Again


  1. Type ‘Package Control’ and select ‘Package Control: Install Package’ (Make sure you are connected to the internet) 



  1. Now type ‘SublimeREPL’ in the search bar and select ‘SublimeREPL’ and wait for it to install.

Now we have to make some minor changes to the config file used by Sublime Text for Python programs. You can find the file by following these steps:

  1. Open Sublime Text 3

  2. Click on ‘Preferences’ and select ‘Browse Packages’


  1. Open the ‘SublimeREPL’ folder

  1. Go to ‘config’ and then the ‘Python’ folder


  1. Open ‘Main.sublime-menu’ with Sublime Text

  1. Press Ctrl + F and search for ‘run’

   7. Now look for "cmd": ["python", "-u", "$file_basename"] and add “-i” (with quotes) so it looks like this after the edit: "cmd": ["python", "-i", "-u", "$file_basename"]

  1. Save the file and exit.

CREATING A CUSTOM BUILD SYSTEM:

We are halfway there now all you have to do is create a new Build System. A build system is what compiles your program. So far, you have been using the default ‘Python’ system to build your programs. This new custom Build System will open an interactive shell every time you build a program. 

There are two ways to accomplish this:

You can either download the file which I have linked below and paste it into the specified directory, or if you are suspicious about the file or if the first method doesn’t work for you, you can create the file by your own by following the given instructions. (BTW Noob Code Pro is totally legit; we only provide safe/official links for use).

Method #1:

  1. Download this file

  2. Open Sublime Text 3

  3. Click on ‘Preferences’ and select ‘Browse Packages’

  1. Go to ‘User’ and paste the file you have downloaded in Step 1 there.

  1. Restart Sublime Text 3

  2. Create a new python file that takes input from the user and save it.

  1. Go to ‘Tools’, ‘Build System’ and select ‘sublimeREPL-python’

  1. And you are done! Now press Ctrl + B to run your program and you will see an interactive shell that opens to take your input and then proceeds to execute the program. This shell will open every time you execute a python program in sublime text.

Method #2:

Let me show you how you can create the file yourself:

  1. Open Subliime Text

  2. Go to ‘Tools’, ‘Build System’ and select ‘New Build System’

  1. Delete the existing content and paste the following code into the new file:

{

    "target": "run_existing_window_command", 

    "id": "repl_python_run",

    "file": "config/Python/Main.sublime-menu"

}

  1. Now save the file as ‘sublimeREPL-python.sublime-build’ or with any other name you want, but the extension should be ‘sublime-build’ and do not change the directory of the file

  1. Restart Sublime Text 3

  2. Create a new python file that takes input from the user and save it.

  3. Go to ‘Tools’, ‘Build System’ and select ‘sublimeREPL-python’ or whatever name you saved the build system with.


CONGRATULATIONS !!! You now know how to execute interactive programs in one of the most used IDEs, Sublime Text. Now, you can execute any program in Sublime Text. We have finally made Sublime Text all good :D.

Let me know, if you loved it, hated it, want to kill me or any other sort of feedback in the comments section below. Also, if you have any queries regarding the topics taught in this lesson or previous lessons, you can always find me in the comments section or in the telegram channel or on my pinterest profile where you can personally talk to me and ask me any question about anything we have learnt so far.

So, this was how you can create a new system build to execute your interactive python programs. Stay tuned for another article next week, same time, where we will discuss about some algorithms, what they are, how they work and where you use them. So more cool stuff coming your way, DON’T MISS IT !! And I'll see you next week. Goodbye and Good Luck :)

I hope this article answered all of your questions and even helped you in becoming a better programmer. IF IT DID, leave a like AND FOLLOW THIS BLOG TO BECOME A PROFESSIONAL PYTHON PROGRAMMER FROM A TOTAL BEGINNER. IF IT DIDN'T, feel free to ask any further queries in the comment section below.


If you are a beginner, intermediate, advanced or just someone interested in programming, feel free to join our telegram channel and be among people like you:


https://t.me/joinchat/AAAAAFVduJs3bF00nwKGUA


And do you know the best part? Joining it is FREE !!!


So go ahead click on the link and I will see you there. 


You can also contact me through my email: code2learnofficial@gmail.com


or


my pinterest profile


 HOPE YOU HAVE AN AWESOME DAY AHEAD !!!