Sublime Forum

New python file comes up empty

#1

When I create a new python file I want it to be filled with basic python template like how TextMate does given below.
Is this possible with Sublime 2?
Thanks!

#!/usr/bin/env python
# encoding: utf-8
"""
utils.py

Created by live on 2013-03-02.
Copyright (c) 2013 __MyCompanyName__. All rights reserved.
"""

import sys
import os


def main():
	pass


if __name__ == '__main__':
	main()
0 Likes

#2

I haven’t tried it before, but perhaps SublimeFileTemplates?

0 Likes

#3

I just tried it and it does not have python template. Do you have suggestions for a python template?

0 Likes

#4

It’s not built in, but you can create it. Skimmed through his example and it looks like you can create the .file-template in your User directory. The content of the template, i believe, is simply a snippet.

0 Likes

#5

Thank you for the reply. I added template as you suggested and got it working. But I am not able to insert todays date into the template.
I searched online and the feedback I got it is, it is not possible to add date.

stackoverflow.com/questions/1187 … me-snippet

Is this right, that I cannot add a date to the tempalte? I have pasted the python template I have:
Also how do I get the current username variable inserted.

#!/usr/bin/env python
# encoding: utf-8
"""
${1:$name}.py

Created by live on 2013-03-02.
Copyright (c) 2013 ${2:__MyCompanyName__}. All rights reserved.
"""

import sys
import os


def main($0):
	pass


if __name__ == '__main__':
	main()
0 Likes

#6

There are a handful of environment variables that are built in and described here (link). Though, I tried using $TM_FULLNAME, which didn’t work. This led me to the following post which describes how to add environment variables (link), though I didn’t test it.

0 Likes