Hello everyone. Today Mingo is here to update PyCharm.
Since March 24th this year, I have updated 7 articles including this one, with 5 tips per article and 35 tips in total.
All the 35 tips I thought were useful when I used PyCharm, so I extracted them and shared them with you. Although some of them were only a small configuration, they saved a lot of time when I used them.
This is the sixth article in this series, and if you haven’t seen the first six, you can check it out here.
1. Share 5 PyCharm per week
2. Share 5 PyCharm per week
3. Share 5 PyCharm per week
4. Share 5 PyCharm per week
5. Share 5 PyCharm per week
6. Share 5 PyCharm per week (6)
Record past exclusive shears
On Windows, there’s a clipboard wizard called Ditto that saves everything you’ve copied and pasted so you can reuse it.
Alfred on the Mac does something similar, of course.
A while back, I happened to find PyCharm on my computer that has a similar feature. You can pull up clipboards like the one below by holding Down Ctrl + Shift + V.
Here I prepared Hello World for several programming languages in advance, which looks like this:
Easy JSON formatting
Here is an unbeautified JSON file. When a JSON file has a lot of content, it is very difficult to extract effective information from it without using a tool to beautify it.
{"profile": {"name":"Ming"."gender": "male"."age": 18."Public Account": "Python Programming Time"."msg": "Welcome to pay attention to my public number!"}}
Copy the code
I often use some of the online sites, such as: tool.oschina.net/codeformat/…
If your computer is not connected to the Internet, or you don’t like to remember one more url, you can use PyCharnm to solve this problem
This is not embellished:
Hold Ctrl+Alt+L and it looks like this
33 Run the Linux command on Windows
There are some differences between the CMD command on Windows and the Linux command. For example, to list all the files in the current directory, dir is used on Windows and ls -l is used on Linux.
For a Linux-based developer like me, the awful experience of all those CMD commands on Windows is unbearable.
In the Bash window that pops up, you can type the Linux command you want to use, which is much more comfortable.
Quick code encapsulation techniques
As the number of lines of code for a main function increases, the code becomes less readable. It is common practice to wrap code into functions based on functionality.
The process is nothing more than
- Define a new function in place
- Copy the original code into this function
- And replace the original code with the function call
If your refactoring is not too heavy, you can always do it manually.
But when you’re refactoring a project’s code, you may need a more efficient encapsulation technique.
PyCharm offers a variety of methods for refactoring code. The most common one is shift+F6. Today I’m going to show you how to refactor a method.
Let’s say I have the following code, and the code highlighted in red is a little out of place in the main function, and it’s not immediately obvious what it’s doing. How to encapsulate it will help us to clarify the logic of the whole main program.
Select the code you want to encapsulate and hold Down Ctrl+Alt+M to pop up the screen below, where you can change the function name, select parameters and return values according to your needs
Click OK and PyCharm will automatically define a function name for you in the appropriate place and place the selected code in it. The parameter names and return values are the same as you requested.
35 Use Git for version management
Go to VCS -> Git -> Clone
Enter git repository information
If you click Test, it will try to connect to the Git server and ask you to enter your login account and password.
After clicking OK, the connection will be successful if everything is normal.
After clicking OK, PyCharm asks you to choose how to open the Git repository directory, in the current window or in a new one.
Since I can have multiple Git repositories under a PyCharm, I chose to open them in the current window for convenience (note that Add to Currently Opened Projects is checked).
Git configuration is complete.
You can now VCS -> Git and see that the previously unavailable grey buttons are available.
This article focuses on the configuration of PyCharm. As for Git operation, it will not be discussed in this article.
If you want to modify the configured Git repository, you can click File -> Setting -> Version Control to bring up the following screen.
I have to say that PyCharm’s UI was done well. I just changed something and submitted it
If you want to continue with this series, you can also follow my Python Programming Time account, where all the articles will be first published, and where I have carefully formatted articles for a good reading experience. You are welcome to subscribe.