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:

VariableDescription
${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看下实例

image

实例02

转载于:https://www.cnblogs.com/infinitecodes/p/11444051.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值