Pycharm文档模板变量
Posted infinitecodes
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Pycharm文档模板变量相关的知识,希望对你有一定的参考价值。
点击这里查看JetBrains官方英文源文件
本篇Blog只是搬运外加大概翻译一下。
File template variables
A file template can contain variables, which are replaced by their values when the template is applied. A variable is a string that starts with a dollar sign $
followed by the variable name. The variable name may optionally be enclosed in curly braces. For example: $MyVariable
and $MyVariable
are different notations of the same variable.
文档模板变量
文档模板可以包含变量,应用模板后,这些变量可以被它们的值替换。一个变量就是一个字符串,这个字符串以一个dollar符”$”开始后接变量名。变量名可以选择用大括号””括起来。如:$MyVariable和$MyVariable是相同的变量但符号不同。
Predefined template variables
The following predefined variables can be used in file templates:
Variable | Description |
$DATE | Current system date |
$DAY | Current day of the month |
$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 |
$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) |
$ORGANIZATION_NAME | Name of your organization specified in the project settings(Ctrl+Shift+Alt+S) |
$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 |
预设模板变量
下表预设的变量可用在文档模板中:
变量 | 描述 |
$DATE | 当前系统日期 |
$DAY | 某个月的当前日 |
$DS | Dollar符$。这个变量用来转义dollar字符,这样它就不会被视为模板变量的前缀 |
$FILE_NAME | 新文件的名称 |
$HOUR | 当前小时 |
$MINUTE | 当前分钟 |
$MONTH | 当前月份 |
$MONTH_NAME_FULL | 当前月份的全称(January, February, 依此类推) |
$MONTH_NAME_SHORT | 当前月份名称的头三个字母(Jan, Feb, 依此类推) |
$NAME | 新实体的名称(文档,类,界面,依此类推) |
$ORGANIZATION_NAME | 在项目设定中指定的单位名称(Ctrl+Shift+Alt+S) |
$PRODUCT_NAME | IDE名称(如:PyCharm) |
$PROJECT_NAME | 当前的项目名 |
$TIME | 当前系统时间 |
$USER | 当前用户的登录名 |
$YEAR | 当前年份 |
Custom template variables
Besides predefined template variables, it is possible to specify custom variables. If necessary, you can define the values of custom variables right in the template using the #set
directive.
For example, if you want to use your full name instead of your login name defined through the predefined variable $USER
, use the following construct:
#set( $MyName = "John Smith" )
If the value of a variable is not defined in the template, PyCharm will ask you to specify it when the template is applied.
定制的模板变量
除了预设定的模板变量,定制的变量也是可以的。必要的话,你可以在模板中使用#set指令
自定义一些变量的值。
举例,如果你想通过预设变量$USER
用你的全名替代你的登录名,就使用下面的语法结构:
#set( $MyName = "John Smith" )
在模板中,如果变量的值没有定义的话,当模板应用后PyCharm会要求你进行设定。
下面我们用PyCharm看下实例
以上是关于Pycharm文档模板变量的主要内容,如果未能解决你的问题,请参考以下文章