6

PyCharm中自定义Python代码模版

 3 years ago
source link: https://chegva.com/4471.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

PyCharm中自定义Python代码模版

打开 Pycharm 设置界面,依次点击 Editor → File and Code Templates → Python Script,输入自定义模板即可,参考如下:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@FileName:    ${NAME}.py
@Function:    
@Author:      Zhihe An
@Site:        https://chegva.com
@Time:        ${DATE}
"""

之后创建python文件就会按模板定义自动添加好头部信息啦

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
 @FileName:    hello world.py
 @Function:    Show me the world!
 @Author:      Zhihe An
 @Site:        https://chegva.com
 @Time:        2021/6/19
"""

Pycharm中预定的模版变量:

The following predefined variables can be used in file templates:

VariableDescription${DATE}Current system date${DAY}Current day of the month${DIR_PATH}Path to the directory of the new file (relative to the project root)${DS}Dollar sign $. This variable is used to escape the dollar character, so that it is not treated as a prefix of a template variable.${FILE_NAME}Name of the new file${HOUR}Current hour${MINUTE}Current minute${SECOND}Current second${MONTH}Current month${MONTH_NAME_FULL}Full name of the current month (January, February, and so on)${MONTH_NAME_SHORT}First three letters of the current month name (Jan, Feb, and so on)${NAME}Name of the new entity (file, class, interface, and so on)${PRODUCT_NAME}Name of the IDE (for example, PyCharm)${PROJECT_NAME}Name of the current project${TIME}Current system time${USER}Login name of the current user${YEAR}Current year

还可以通过 #set 定义自定义变量,详情参考官网文档:

anzhihe安志合个人博客,版权所有丨 如未注明,均为原创 丨转载请注明转自:https://chegva.com/4471.html | ☆★★每天进步一点点,加油!★★☆

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK