前言
追求效率和便利应该是我们永久不变的信仰。今天就为大家介绍一个PyCharm的设置技巧,可以减少我们在新建python文件时的一些繁琐的设置。
应用场景
新建文件时自动设置文件头部模板。
操作步骤
File->settings->Editor->File and Code Templates然后在右侧选择"Files",找到“Python Script”
# encoding: utf-8
"""
@author: Micheal
@contact: salc3k@qq.com
@site: lantingtalk.com
@file: ${NAME}.py
@time: ${DATE} ${TIME}
"""
可使用的预置文件模板变量有:
${PROJECT_NAME}
- the name of the current project.
${NAME}
- the name of the new file which you specify in the New Filedialog box during the file creation.
${USER}
- the login name of the current user.
${DATE}
- the current system date.
${TIME}
- the current system time.
${YEAR}
- the current year.
${MONTH}
- the current month.
${DAY}
- the current day of the month.
${HOUR}
- the current hour.
${MINUTE}
- the current minute.
${PRODUCT_NAME}
- the name of the IDE in which the file will be created.
${MONTH_NAME_SHORT}
- the first 3 letters of the month name. Example: Jan, Feb, etc.
${MONTH_NAME_FULL}
- full name of a month. Example: January, February, etc.
自定义变量:
#set( $SITE = "http://lantingtalk.com" )
"""
@version: python2.7
@author: ‘$USER‘
@license: Apache Licence
@contact: 369023466@qq.com
@site: ${SITE}
@software: ${PRODUCT_NAME}
@file: ${NAME}.py
@time: ${DATE} ${TIME}
"""
Custom variables. Their names can be defined right in the template through the #set
directive or will be defined during the file creation.
To have the dollar character ($
) in a variable rendered "as is", use the${DS}
variable instead. This variable evaluates to a plain dollar character ($
).
Apply the changes and close the dialog box.
网友评论