Pycharm自动生成代码

当你使用Pycharm新建文件时,它会生成一个空白文件。可能你需要让它填充一些共用的代码,比如文件头、类的声明语句等

Pycharm的文件模版就是解决这个问题的,下面以python代码为例

1 打开设置(Preference)->编辑(Editor)->文件代码模版(File and Code Templates)->点击“+”


image.png

2 如图分别输入模版名,后缀,以及文本内容


image.png

3 保存
4 试试文件模版是否好用

在项目右键然后选择新建文件即可看到文件模版


image.png

5 输入文件名后确认,新文件出现了
image.png

6 补充文件模版示例代码与可用的变量

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
 @desc:
 @author: ${USER}
 @software: PyCharm  on ${DATE}
"""
可用变量

Variable

Description

${DATE}
Current system date

${DAY}
Current day of the month

${END}
Caret position after you finish editing the variables

${HOUR}
Current hour

${MINUTE}
Current minute

${MONTH}
Current month

${MONTH_NAME_FULL}
Full name of the current month (January, February, etc.)

${MONTH_NAME_SHORT}
First three letters of the current month name (Jan, Feb, etc.)

${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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容