Home Download Buy Blog Forum Support

New python file comes up empty

New python file comes up empty

Postby kevin3210 on Sun Mar 03, 2013 7:11 am

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!


Code: Select all
#!/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()

kevin3210
 
Posts: 3
Joined: Tue May 18, 2010 1:38 am

Re: New python file comes up empty

Postby skuroda on Sun Mar 03, 2013 8:01 am

I haven't tried it before, but perhaps SublimeFileTemplates?
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: New python file comes up empty

Postby kevin3210 on Sun Mar 03, 2013 8:19 am

I just tried it and it does not have python template. Do you have suggestions for a python template?
Attachments
Screen Shot 2013-03-02 at 11.55.09 PM.png
Screen Shot 2013-03-02 at 11.55.09 PM.png (16.67 KiB) Viewed 1216 times
kevin3210
 
Posts: 3
Joined: Tue May 18, 2010 1:38 am

Re: New python file comes up empty

Postby skuroda on Sun Mar 03, 2013 8:42 am

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.
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: New python file comes up empty

Postby kevin3210 on Sun Mar 03, 2013 10:31 am

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.

http://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.




Code: Select all
#!/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()
kevin3210
 
Posts: 3
Joined: Tue May 18, 2010 1:38 am

Re: New python file comes up empty

Postby skuroda on Sun Mar 03, 2013 8:00 pm

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.
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 27 guests