头信息自动添加

每次写Header部分真的很烦,即使每次都只是从原来写好的模板上复制过来改一改,都是一件很麻烦的事情,时间浪费在这种琐碎的事情上真的很不值得。这篇记录自己平时使用Pycharm的一个小技巧吧,如何在创建文件时候自动添加文件信息,时间,工程信息还有个人的一些信息,希望能节省下大家一些宝贵的时间。

这种小技巧,可能真的很简单,可是真的非常有用,还有必要分享一下。

操作

按照下面的顺序操作:

Pycharm →→ File→→Settings→→Editor→→File and code Templates

在右侧的选项中找到Python Script,如下图:
mark

在右侧输入你想要的模板格式,拿我的举例,实现了自动添加文件名称,时间自动填充:
mark

如果每天手打这些东西是真的很累,即使是复制,日积月累的工作量也并不小的。

语法

$ {<variable_name>}

预定义变量

下面列举下IDE中预先定义好的变量。

${PROJECT_NAME} - the name of the current project.
${NAME} - the name of the new file which you specify in the New File dialog 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.

更改预变量

预定义变量也是可以自己进行更改的,当然自己创建变量再引用也是完全OK的,但有什么必要呢,直接写死不就好了。

#set($USER = "Handsome")

Hearder还是很重要的,我的头格式仅仅对大家当作一个参考,内容不多,希望对大家能有所帮助。

-------------本文结束感谢您的阅读-------------