当你使用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
网友评论