Selected from RealPython

By Jahongir Rahmonov

Heart of the machine compiles

Participation: Demon Lord

PyCharm is a Python IDE that helps programmers save time and increase productivity. So how to use it? PyCharm installation, plug-ins, external tools, and professional features are all covered in this article.

  • PyCharm installation

  • Write code in PyCharm

  • Run the code in PyCharm

  • Debug and test your code in PyCharm

  • Edit existing projects in PyCharm

  • Search and navigate in PyCharm

  • Use version control in PyCharm

  • Use plug-ins and external tools in PyCharm

  • Use PyCharm Professional features such as Django support and Science mode

PyCharm installation

Write code in PyCharm



Run the code in PyCharm

  1. On a Mac OS, press Ctrl+Shift+R. On a Windows OR Linux OS, press Ctrl+Shift+F10.

  2. Right-click on the background and choose “Run” guess_game “from the menu.

  3. Since the program has a __main__ clause, you can click on the small green arrow to the left of the __main__ clause and select “Run” guess_game “.

Debug your code in PyCharm

  1. On Mac, press Ctrl+Shift+D; on Windows or Linux, press Shift+Alt+F9.

  2. Right-click the background and choose Debug “Guess_game”.

  3. Click the small green arrow to the left of the __main__ clause and select “Debug” guess_game “.


  1. Notice that the current row is highlighted in blue.

  2. The Debug window displays random_int and its value. Record the number. (The figure above is 85.)

  3. Click F8 to execute the current line of code and proceed to the next line of code. If necessary, you can also use F7 to jump to functions in the current line. As you continue to execute the statement, variable changes are automatically displayed in the Debugger window.

  4. Notice that there is a Console label to the right of the Debugger label. Console labels and Debugger labels are independent of each other. You can interact with programs in the Console and perform debug actions in the Debugger.

  5. Turn to the Console TAB and enter the guessing process.

  6. Type the number displayed in the left Debugger TAB and press Enter.

  7. Go back to the Debugger TAB.

  8. Click F8 again to evaluate the if statement. Notice now you’re on line 14. Why not line 11? Because the if statement on line 10 evaluates to False. So why does it work out to be False when you type in the number?

  9. Take a close look at line 10 and notice that we are comparing user_guess with an incorrect entry. We should compare the user’s guess with random_int, but here we compare randINT (the function imported from the Random package).

  10. Change randINT to random_int and follow the same steps to restart debug. You’ll notice that this time you get to line 11, and line 10 evaluates to True:

Test the code in PyCharm

  1. Open the Settings/Preferences → Tools → Python Integrated Tools dialog box.

  2. Select PyTest in the default test runner field.

  3. Click OK to save the setting.

  • On Mac, press Shift+Cmd+T. On Windows or Linux, press Ctrl+Shift+T.

  • Right-click the background of the class and choose Go To and Test.

  • Navigate → Test in the main menu.


  • Use Ctrl+R on a Mac, Shift+F10 on Windows or Linux.

  • Right-click on the background and select “Run” Unittests for test_calculator.py “.

  • Click the small green arrow to the left of the test class name and select “Run” Unittests for test_Calculator.py “.


Edit existing projects in PyCharm

  • From the main menu, click File → Open.

  • Click Open on the welcome page.


Search and navigate in PyCharm

  • Search for code snippets in the current file: Use Cmd+F on a Mac, Ctrl+F on Windows or Linux.

  • Search for code snippets throughout the project: Use Cmd+Shift+F on Mac, Ctrl+Shift+F on Windows or Linux.

  • Search: Press Cmd+O on a Mac operating system, Ctrl+N on a Windows or Linux operating system.

  • Search for files: On a Mac, press Cmd+Shift+O; on a Windows or Linux, press Ctrl+Shift+N.

  • If you don’t know if you’re searching for files, classes, or code snippets, search all of them: Press Shift twice.

  • Go to the declaration of variables: On a Mac system use the Cmd key, on a Windows or Linux system use the Ctrl key, and then click the variable.

  • Find usage of classes, methods, or files: Use Alt+F7 keys.

  • To see Recent Changes: Use Shift+Alt+C or click View → Recent Changes from the main menu.

  • To View Recent Files: Use Cmd+E on a Mac, Ctrl+E on Windows or Linux, or click View → Recent Files from the main menu.

  • Press Cmd+[/ Cmd+] on a Mac operating system, Ctrl+Alt+Left/Ctrl+Alt+Right on a Windows or Linux operating system.

Version control in PyCharm
Configuring the Version Control System (VCS)


Commit and conflict handling

  • Select the file to submit

  • Write the submission information

  • Perform checks prior to submission

  • See the changes

  • Click the arrow next to the Commit button in the lower right corner and select Commit and Push… To complete the commit and push in one go.


Use plug-ins and external tools in PyCharm

  • Added support for multiple languages and frameworks

  • Use shortcut Hints, file Watcher, etc to increase your productivity

  • Use code exercises to help you learn new programming languages








PyCharm Professional function
Django support

  1. Open Preferences in a Mac system and Settings in a Windows or Linux system.

  2. Choose Languages and Frameworks.

  3. Select the Django.

  4. Check the check box Enable Django Support.

  5. Apply the changes.

  • Syntax and errors are highlighted

  • Code completion

  • navigation

  • Block name completion

  • Customize labels and filter completion

  • Quick documentation of labels and filters

  • Template debug capability

Database support

Thread Concurrency Visualization
Profiler
Scientific mode


Remote development

conclusion

The original address: https://realpython.com/pycharm-guide/

this Compiled for the heart of the machine,Reprint please contact this official number for authorization .
Join Heart of the Machine (full-time reporter/intern) : [email protected]
Contribute or seek coverage:content@jiqizhixin.com
Advertising & Business partnerships: [email protected]