Pycharm advanced configuration custom files, method templates

reference

https://blog.csdn.net/mouday/article/details/80515308
https://blog.csdn.net/dkjkls/article/details/88933950

Custom file template

pycharm file template

Entry:
Preferences --> Editor ---> File and Code Templates --> Python Script

Paste into custom file header

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File    :   ${NAME}.py    
@Contact :   [email protected]
@Author  :   name
@Modify Time      @Version    @Desciption
------------      --------    -----------
${DATE} ${TIME}    1.0         None
"""

Variable NAME DATE TIME comes with pycharm editor

The above information will be added automatically after the newly created file

Reference to other variables:

${PROJECT_NAME} - 当前的项目名  
${NAME} - 在文件创建过程中,新文件对话框的命名  
${USER} - 当前的登录用户  
${DATE} - 现在的系统日期  
${TIME} - 现在的系统时间  
${YEAR} - 当前年份  
${MONTH} - 当前月份  
${DAY} - 当前月份中的第几日  
${HOUR} - 现在的小时  
${MINUTE} - 现在的分钟  
${PRODUCT_NAME} - IDE创建文件的名称  
${MONTH_NAME_SHORT} - 月份的前三个字母缩写  
${MONTH_NAME_FULL} - 完整的月份名

Style reference

# -*- coding: utf-8 -*-#

#-------------------------------------------------------------------------------
# Name:         ${NAME}
# Description:  
# Author:       ${USER}
# Date:         ${DATE}
#-------------------------------------------------------------------------------

docstring documentation for pycharm

Set location:
Preferences -> Tools -> Python Integrated Tools -> Docstrings -> Docstring format

Five styles:

Plain
reStructuredText
Numpy
Google
Epytext
style example

# Plain
 	def foo1(a, b):
 	    """	
 	    """
 	    return a+b	
	# reStructuredText
  def foo2(a, b):
      """
      :param a:
      :param b:
      :return:
      """
      return a+b

  # Numpy
  def foo3(a, b):
      """
      Parameters
      ----------
      a
      b

      Returns
      -------
    
      """
      return a+b

  # Google
  def foo4(a, b):
      """
      Args:
          a:
          b:

      Returns:
    
      """
      return a + b

  # Epytext
  def foo(a, b):
      """
      @param a:
      @param b:
      @return:
      """
      return a+b

Add method notes to customize global shortcuts

Docstring format can automatically format and output docstrings, but can not add the creator, creation time, modifier, modification time, copyright notice; some specifications suggest that these elements are written in the head of the file, but for collaborative development of the same file, feel These elements need to be added to each method to make it clearer.

Can be achieved through pyCharm's Live Templates custom template.
The setting path in Live Templates is as follows:
File -> Settings -> Editor -> Live Templates

Click to +create a new template, and a user group will be automatically generated. Abbreviation represents the shortcut key, and Description describes it.

After setting the shortcut keys, you need to set the scope of use and add template content. If you use variables, you need to set the variables and then save the
scope of application

Set variables

General use scope, variables, and template content all need to be set

Template file reference:

:now_time: $DATE$ $TIME$
"""

Parameters
----------

Returns
-------

Examples
--------

--------
:Author:  lduml
:Create:  $DATE$ $TIME$
"""

Guess you like

Origin www.cnblogs.com/lduml/p/12681821.html