2012-08-17 03:41:25 +00:00
|
|
|
snippet #!
|
|
|
|
#!/usr/bin/env python
|
2014-04-18 12:58:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-12-08 13:20:04 +00:00
|
|
|
snippet #!3
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
2012-08-17 03:41:25 +00:00
|
|
|
snippet imp
|
2013-11-16 19:45:48 +00:00
|
|
|
import ${0:module}
|
2013-07-17 23:06:05 +00:00
|
|
|
snippet uni
|
|
|
|
def __unicode__(self):
|
2013-11-16 19:45:48 +00:00
|
|
|
${0:representation}
|
2012-08-17 03:41:25 +00:00
|
|
|
snippet from
|
2013-11-16 19:45:48 +00:00
|
|
|
from ${1:package} import ${0:module}
|
2012-08-17 03:41:25 +00:00
|
|
|
# Module Docstring
|
|
|
|
snippet docs
|
2013-04-13 17:45:21 +00:00
|
|
|
"""
|
2013-07-17 23:06:05 +00:00
|
|
|
File: ${1:`vim_snippets#Filename('$1.py', 'foo.py')`}
|
2013-04-13 17:45:21 +00:00
|
|
|
Author: `g:snips_author`
|
|
|
|
Email: `g:snips_email`
|
|
|
|
Github: `g:snips_github`
|
2013-11-16 19:45:48 +00:00
|
|
|
Description: ${0}
|
2013-04-13 17:45:21 +00:00
|
|
|
"""
|
2013-07-17 23:06:05 +00:00
|
|
|
|
2012-08-17 03:41:25 +00:00
|
|
|
snippet wh
|
|
|
|
while ${1:condition}:
|
2017-02-11 13:01:38 +00:00
|
|
|
${0:${VISUAL}}
|
2012-08-17 03:41:25 +00:00
|
|
|
# dowh - does the same as do...while in other languages
|
|
|
|
snippet dowh
|
|
|
|
while True:
|
2013-07-17 23:06:05 +00:00
|
|
|
${1}
|
2013-11-16 19:45:48 +00:00
|
|
|
if ${0:condition}:
|
2012-08-17 03:41:25 +00:00
|
|
|
break
|
|
|
|
snippet with
|
|
|
|
with ${1:expr} as ${2:var}:
|
2017-02-11 13:01:38 +00:00
|
|
|
${0:${VISUAL}}
|
2017-11-24 13:54:40 +00:00
|
|
|
snippet awith
|
|
|
|
async with ${1:expr} as ${2:var}:
|
|
|
|
${0:${VISUAL}}
|
2012-08-17 03:41:25 +00:00
|
|
|
# New Class
|
|
|
|
snippet cl
|
|
|
|
class ${1:ClassName}(${2:object}):
|
|
|
|
"""${3:docstring for $1}"""
|
|
|
|
def __init__(self, ${4:arg}):
|
|
|
|
${5:super($1, self).__init__()}
|
|
|
|
self.$4 = $4
|
2013-11-16 19:45:48 +00:00
|
|
|
${0}
|
2012-08-17 03:41:25 +00:00
|
|
|
# New Function
|
|
|
|
snippet def
|
|
|
|
def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
|
|
|
|
"""${3:docstring for $1}"""
|
2013-11-16 19:45:48 +00:00
|
|
|
${0}
|
2012-08-17 03:41:25 +00:00
|
|
|
snippet deff
|
|
|
|
def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
|
2013-11-16 19:45:48 +00:00
|
|
|
${0}
|
2017-11-24 13:54:40 +00:00
|
|
|
snippet adef
|
|
|
|
async def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
|
|
|
|
"""${3:docstring for $1}"""
|
|
|
|
${0}
|
|
|
|
snippet adeff
|
|
|
|
async def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
|
|
|
|
${0}
|
2012-08-17 03:41:25 +00:00
|
|
|
# New Method
|
2015-07-13 10:22:46 +00:00
|
|
|
snippet defm
|
2012-08-17 03:41:25 +00:00
|
|
|
def ${1:mname}(self, ${2:arg}):
|
2013-11-16 19:45:48 +00:00
|
|
|
${0}
|
2017-11-24 13:54:40 +00:00
|
|
|
snippet adefm
|
|
|
|
async def ${1:mname}(self, ${2:arg}):
|
|
|
|
${0}
|
|
|
|
|
2012-08-17 03:41:25 +00:00
|
|
|
# New Property
|
|
|
|
snippet property
|
|
|
|
def ${1:foo}():
|
|
|
|
doc = "${2:The $1 property.}"
|
|
|
|
def fget(self):
|
|
|
|
${3:return self._$1}
|
|
|
|
def fset(self, value):
|
|
|
|
${4:self._$1 = value}
|
2013-04-13 17:45:21 +00:00
|
|
|
def fdel(self):
|
2013-11-16 19:45:48 +00:00
|
|
|
${0:del self._$1}
|
2013-04-13 17:45:21 +00:00
|
|
|
return locals()
|
|
|
|
$1 = property(**$1())
|
2012-08-17 03:41:25 +00:00
|
|
|
# Ifs
|
|
|
|
snippet if
|
|
|
|
if ${1:condition}:
|
2017-02-11 13:01:38 +00:00
|
|
|
${0:${VISUAL}}
|
2012-08-17 03:41:25 +00:00
|
|
|
snippet el
|
|
|
|
else:
|
2017-02-11 13:01:38 +00:00
|
|
|
${0:${VISUAL}}
|
2012-08-17 03:41:25 +00:00
|
|
|
snippet ei
|
|
|
|
elif ${1:condition}:
|
2017-02-11 13:01:38 +00:00
|
|
|
${0:${VISUAL}}
|
2012-08-17 03:41:25 +00:00
|
|
|
# For
|
|
|
|
snippet for
|
|
|
|
for ${1:item} in ${2:items}:
|
2013-11-16 19:45:48 +00:00
|
|
|
${0}
|
2012-08-17 03:41:25 +00:00
|
|
|
# Encodes
|
|
|
|
snippet cutf8
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
snippet clatin1
|
|
|
|
# -*- coding: latin-1 -*-
|
|
|
|
snippet cascii
|
|
|
|
# -*- coding: ascii -*-
|
|
|
|
# Lambda
|
2013-07-17 23:06:05 +00:00
|
|
|
snippet ld
|
2013-11-16 19:45:48 +00:00
|
|
|
${1:var} = lambda ${2:vars} : ${0:action}
|
2017-12-13 14:05:24 +00:00
|
|
|
snippet ret
|
|
|
|
return ${0}
|
2012-08-17 03:41:25 +00:00
|
|
|
snippet .
|
|
|
|
self.
|
|
|
|
snippet try Try/Except
|
|
|
|
try:
|
2017-02-11 13:01:38 +00:00
|
|
|
${1:${VISUAL}}
|
|
|
|
except ${2:Exception} as ${3:e}:
|
2013-11-16 19:45:48 +00:00
|
|
|
${0:raise $3}
|
2012-08-17 03:41:25 +00:00
|
|
|
snippet try Try/Except/Else
|
|
|
|
try:
|
2017-02-11 13:01:38 +00:00
|
|
|
${1:${VISUAL}}
|
|
|
|
except ${2:Exception} as ${3:e}:
|
2012-08-17 03:41:25 +00:00
|
|
|
${4:raise $3}
|
|
|
|
else:
|
2013-11-16 19:45:48 +00:00
|
|
|
${0}
|
2012-08-17 03:41:25 +00:00
|
|
|
snippet try Try/Except/Finally
|
|
|
|
try:
|
2017-02-11 13:01:38 +00:00
|
|
|
${1:${VISUAL}}
|
|
|
|
except ${2:Exception} as ${3:e}:
|
2012-08-17 03:41:25 +00:00
|
|
|
${4:raise $3}
|
|
|
|
finally:
|
2013-11-16 19:45:48 +00:00
|
|
|
${0}
|
2012-08-17 03:41:25 +00:00
|
|
|
snippet try Try/Except/Else/Finally
|
|
|
|
try:
|
2017-02-11 13:01:38 +00:00
|
|
|
${1:${VISUAL}}
|
|
|
|
except ${2:Exception} as ${3:e}:
|
2012-08-17 03:41:25 +00:00
|
|
|
${4:raise $3}
|
|
|
|
else:
|
2013-07-17 23:06:05 +00:00
|
|
|
${5}
|
2012-08-17 03:41:25 +00:00
|
|
|
finally:
|
2013-11-16 19:45:48 +00:00
|
|
|
${0}
|
2012-08-17 03:41:25 +00:00
|
|
|
# if __name__ == '__main__':
|
|
|
|
snippet ifmain
|
|
|
|
if __name__ == '__main__':
|
2013-11-16 19:45:48 +00:00
|
|
|
${0:main()}
|
2012-08-17 03:41:25 +00:00
|
|
|
# __magic__
|
|
|
|
snippet _
|
2013-11-16 19:45:48 +00:00
|
|
|
__${1:init}__
|
2012-08-17 03:41:25 +00:00
|
|
|
# python debugger (pdb)
|
|
|
|
snippet pdb
|
2017-11-24 13:54:40 +00:00
|
|
|
__import__('pdb').set_trace()
|
2016-02-20 13:13:10 +00:00
|
|
|
# bpython debugger (bpdb)
|
|
|
|
snippet bpdb
|
2017-11-24 13:54:40 +00:00
|
|
|
__import__('bpdb').set_trace()
|
2012-08-17 03:41:25 +00:00
|
|
|
# ipython debugger (ipdb)
|
|
|
|
snippet ipdb
|
2017-11-24 13:54:40 +00:00
|
|
|
__import__('ipdb').set_trace()
|
2015-01-18 12:58:28 +00:00
|
|
|
# embed ipython itself
|
|
|
|
snippet iem
|
2017-11-24 13:54:40 +00:00
|
|
|
__import__('IPython').embed()
|
2015-02-04 10:43:54 +00:00
|
|
|
# remote python debugger (rpdb)
|
|
|
|
snippet rpdb
|
2017-11-24 13:54:40 +00:00
|
|
|
__import__('rpdb').set_trace()
|
2017-05-02 12:42:08 +00:00
|
|
|
# web python debugger (wdb)
|
|
|
|
snippet wdb
|
2017-11-24 13:54:40 +00:00
|
|
|
__import__('wdb').set_trace()
|
2015-07-13 10:22:46 +00:00
|
|
|
# ptpython
|
|
|
|
snippet ptpython
|
2017-11-24 13:54:40 +00:00
|
|
|
__import__('ptpython.repl', fromlist=('repl')).embed(globals(), locals(), vi_mode=${1:False}, history_filename=${2:None})
|
2013-07-17 23:06:05 +00:00
|
|
|
# python console debugger (pudb)
|
|
|
|
snippet pudb
|
2017-11-24 13:54:40 +00:00
|
|
|
__import__('pudb').set_trace()
|
2015-12-08 13:20:04 +00:00
|
|
|
# pdb in nosetests
|
|
|
|
snippet nosetrace
|
2017-11-24 13:54:40 +00:00
|
|
|
__import__('nose').tools.set_trace()
|
2012-08-17 03:41:25 +00:00
|
|
|
snippet pprint
|
2017-11-24 13:54:40 +00:00
|
|
|
__import__('pprint').pprint(${1})
|
2012-08-17 03:41:25 +00:00
|
|
|
snippet "
|
2015-07-13 10:22:46 +00:00
|
|
|
"""${0:doc}
|
2012-08-17 03:41:25 +00:00
|
|
|
"""
|
2013-11-16 19:45:48 +00:00
|
|
|
# assertions
|
|
|
|
snippet a=
|
|
|
|
self.assertEqual(${0}, ${1})
|
2012-08-17 03:41:25 +00:00
|
|
|
# test function/method
|
|
|
|
snippet test
|
|
|
|
def test_${1:description}(${2:`indent('.') ? 'self' : ''`}):
|
2013-11-16 19:45:48 +00:00
|
|
|
${0}
|
2012-08-17 03:41:25 +00:00
|
|
|
# test case
|
|
|
|
snippet testcase
|
|
|
|
class ${1:ExampleCase}(unittest.TestCase):
|
2013-07-17 23:06:05 +00:00
|
|
|
|
2012-08-17 03:41:25 +00:00
|
|
|
def test_${2:description}(self):
|
2013-11-16 19:45:48 +00:00
|
|
|
${0}
|
2017-11-24 13:54:40 +00:00
|
|
|
# test given when then
|
|
|
|
snippet tgwt
|
|
|
|
# given: ${1}
|
|
|
|
# when: ${2}
|
|
|
|
# then: ${3}
|
2012-08-17 03:41:25 +00:00
|
|
|
snippet fut
|
2013-11-16 19:45:48 +00:00
|
|
|
from __future__ import ${0}
|
2013-04-13 17:45:21 +00:00
|
|
|
#getopt
|
|
|
|
snippet getopt
|
|
|
|
try:
|
|
|
|
# Short option syntax: "hv:"
|
|
|
|
# Long option syntax: "help" or "verbose="
|
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "${1:short_options}", [${2:long_options}])
|
2013-07-17 23:06:05 +00:00
|
|
|
|
2013-04-13 17:45:21 +00:00
|
|
|
except getopt.GetoptError, err:
|
|
|
|
# Print debug info
|
|
|
|
print str(err)
|
|
|
|
${3:error_action}
|
|
|
|
|
|
|
|
for option, argument in opts:
|
|
|
|
if option in ("-h", "--help"):
|
2013-11-16 19:45:48 +00:00
|
|
|
${0}
|
2013-04-13 17:45:21 +00:00
|
|
|
elif option in ("-v", "--verbose"):
|
|
|
|
verbose = argument
|
2013-05-26 00:31:29 +00:00
|
|
|
# logging
|
|
|
|
# glog = get log
|
|
|
|
snippet glog
|
|
|
|
import logging
|
2017-11-24 13:54:40 +00:00
|
|
|
LOGGER = logging.getLogger(${0:__name__})
|
2013-05-26 00:31:29 +00:00
|
|
|
snippet le
|
2017-11-24 13:54:40 +00:00
|
|
|
LOGGER.error(${0:msg})
|
2013-07-17 23:06:05 +00:00
|
|
|
# conflict with lambda=ld, therefor we change into Logger.debuG
|
|
|
|
snippet lg
|
2017-11-24 13:54:40 +00:00
|
|
|
LOGGER.debug(${0:msg})
|
2013-05-26 00:31:29 +00:00
|
|
|
snippet lw
|
2017-11-24 13:54:40 +00:00
|
|
|
LOGGER.warning(${0:msg})
|
2013-05-26 00:31:29 +00:00
|
|
|
snippet lc
|
2017-11-24 13:54:40 +00:00
|
|
|
LOGGER.critical(${0:msg})
|
2013-05-26 00:31:29 +00:00
|
|
|
snippet li
|
2017-11-24 13:54:40 +00:00
|
|
|
LOGGER.info(${0:msg})
|
2013-08-03 12:50:12 +00:00
|
|
|
snippet epydoc
|
2015-07-13 10:22:46 +00:00
|
|
|
"""${1:Description}
|
2013-08-03 12:50:12 +00:00
|
|
|
|
|
|
|
@param ${2:param}: ${3: Description}
|
|
|
|
@type $2: ${4: Type}
|
|
|
|
|
|
|
|
@return: ${5: Description}
|
|
|
|
@rtype : ${6: Type}
|
|
|
|
|
2013-11-16 19:45:48 +00:00
|
|
|
@raise e: ${0: Description}
|
2013-08-03 12:50:12 +00:00
|
|
|
"""
|
2014-04-18 12:58:02 +00:00
|
|
|
snippet dol
|
|
|
|
def ${1:__init__}(self, *args, **kwargs):
|
|
|
|
super(${0:ClassName}, self).$1(*args, **kwargs)
|
|
|
|
snippet kwg
|
|
|
|
self.${1:var_name} = kwargs.get('$1', ${2:None})
|
|
|
|
snippet lkwg
|
|
|
|
${1:var_name} = kwargs.get('$1', ${2:None})
|
2015-01-18 12:58:28 +00:00
|
|
|
snippet args
|
|
|
|
*args${1:,}${0}
|
|
|
|
snippet kwargs
|
|
|
|
**kwargs${1:,}${0}
|
|
|
|
snippet akw
|
|
|
|
*args, **kwargs${1:,}${0}
|
2017-11-24 13:54:40 +00:00
|
|
|
|
|
|
|
# comprehensions
|
|
|
|
snippet lcp list comprehension
|
|
|
|
[${1} for ${2} in ${3:${VISUAL}}]${0}
|
|
|
|
|
|
|
|
snippet dcp dict comprehension
|
|
|
|
{${1}: ${2} for ${3} in ${4:${VISUAL}}}${0}
|
|
|
|
|
|
|
|
snippet scp set comprehension
|
|
|
|
{${1} for ${2} in ${3:${VISUAL}}}${0}
|