Preface
The previous article introduced how to install python programs. This time I will talk about how to use sublime to write python code.
Some friends may have questions, why not choose pycharm to write?
Pycharm will have a code completion function when writing code, and we novices need to accumulate experience in the process of making mistakes. Therefore, in the early stage, it is best for us novices to use text compilers such as sublime, notepad, and vscode to write code. In order to improve the efficiency of writing code later, we will use an editor such as pycharm.
1. Use sublime text in windows system
Download address
https://www.sublimetext.com/3
(Note: The genuine sublime text editor requires payment)
The installation of sublime is very simple, there is nothing to pay attention to, just "Next" all the way.
Note: It is recommended to download and install the software to a location other than C drive, that is, D drive or E drive, and you must be able to remember the installation location.
2. Run the python program in sublime text
2.1 Code writing and saving
(Note: The brackets and double quotes entered are all English characters, otherwise grammatical errors will occur!)
Then press CTRL+S or click Save in the middle of the file and save it as a file with a .py suffix. Save the
written python file to a location you can remember. This location should be in English as much as possible, and no Chinese characters should appear, otherwise the code will run later. There will be problems!
2.2 Run python file
Any friends may ask? How to compile and run python code program in sublime? Isn’t this how to operate it already?
The first method: compile and run directly in sublime
Select Tools in the menu bar, select Build system, and select python
Press the shortcut key CTRL+B or press "Compile Now" in the tool to execute the running code
Second method: Use the cmd command line in the windows system to execute the python script (i.e. .py file)
Press Windows+R to bring up the run window, enter cmd, click "OK", or press Enter (enter key)
3. Customize the settings of sublime text
3.1 Convert tabs to spaces
Select menu view->indentation and verify that the checkbox indent using spaces is selected. If the checkbox is not selected, select it now.
3.2 Set the line length flag
Select menu view->ruler, then click 80. Sublime Text will place a vertical line at the 80 character mark.
3.3 Indent and unindent code blocks
To indent a code block, select it and then select the menu edit->line->indent or press ctrl+]
To cancel the code block, select the menu edit->line->unindent or press ctrl+[
3.4 Comment out code blocks
To comment out the code block, select it, then select edit->comment->toggle comment or ctrl+/
to uncomment the code block, execute this command again
Okay, that’s the end of today’s sharing! If you think it’s good, please give it a like! ! !