aboutsummaryrefslogtreecommitdiff
path: root/vim/bundle/vim-snippets/snippets/python.snippets
blob: 0f68acbd4a42960c55c0ca38ea08370f8acb4d3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
snippet #!
	#!/usr/bin/env python
	# -*- coding: utf-8 -*-
snippet #!3
	#!/usr/bin/env python3
	# -*- coding: utf-8 -*-
snippet imp
	import ${0:module}
snippet uni
	def __unicode__(self):
		${0:representation}
snippet from
	from ${1:package} import ${0:module}
# Module Docstring
snippet docs
	"""
	File: ${1:`vim_snippets#Filename('$1.py', 'foo.py')`}
	Author: `g:snips_author`
	Email: `g:snips_email`
	Github: `g:snips_github`
	Description: ${0}
	"""

snippet wh
	while ${1:condition}:
		${0}
# dowh - does the same as do...while in other languages
snippet dowh
	while True:
		${1}
		if ${0:condition}:
			break
snippet with
	with ${1:expr} as ${2:var}:
		${0}
# 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
			${0}
# New Function
snippet def
	def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
		"""${3:docstring for $1}"""
		${0}
snippet deff
	def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
		${0}
# New Method
snippet defm
	def ${1:mname}(self, ${2:arg}):
		${0}
# 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}
		def fdel(self):
			${0:del self._$1}
		return locals()
	$1 = property(**$1())
# Ifs
snippet if
	if ${1:condition}:
		${0}
snippet el
	else:
		${0}
snippet ei
	elif ${1:condition}:
		${0}
# For
snippet for
	for ${1:item} in ${2:items}:
		${0}
# Encodes
snippet cutf8
	# -*- coding: utf-8 -*-
snippet clatin1
	# -*- coding: latin-1 -*-
snippet cascii
	# -*- coding: ascii -*-
# Lambda
snippet ld
	${1:var} = lambda ${2:vars} : ${0:action}
snippet .
	self.
snippet try Try/Except
	try:
		${1}
	except ${2:Exception}, ${3:e}:
		${0:raise $3}
snippet try Try/Except/Else
	try:
		${1}
	except ${2:Exception}, ${3:e}:
		${4:raise $3}
	else:
		${0}
snippet try Try/Except/Finally
	try:
		${1}
	except ${2:Exception}, ${3:e}:
		${4:raise $3}
	finally:
		${0}
snippet try Try/Except/Else/Finally
	try:
		${1}
	except ${2:Exception}, ${3:e}:
		${4:raise $3}
	else:
		${5}
	finally:
		${0}
# if __name__ == '__main__':
snippet ifmain
	if __name__ == '__main__':
		${0:main()}
# __magic__
snippet _
	__${1:init}__
# python debugger (pdb)
snippet pdb
	import pdb
	pdb.set_trace()
# bpython debugger (bpdb)
snippet bpdb
	import bpdb
	bpdb.set_trace()
# ipython debugger (ipdb)
snippet ipdb
	import ipdb
	ipdb.set_trace()
# embed ipython itself
snippet iem
	import IPython
	IPython.embed()
# ipython debugger (pdbbb)
snippet pdbbb
	import pdbpp
	pdbpp.set_trace()
# remote python debugger (rpdb)
snippet rpdb
	import rpdb
	rpdb.set_trace()
# ptpython
snippet ptpython
	from ptpython.repl import embed
	embed(globals(), locals(), vi_mode=${1:False}, history_filename=${2:None})
# python console debugger (pudb)
snippet pudb
	import pudb
	pudb.set_trace()
# pdb in nosetests
snippet nosetrace
	from nose.tools import set_trace
	set_trace()
snippet pprint
	import pprint
	pprint.pprint(${1})
snippet "
	"""${0:doc}
	"""
# assertions
snippet a=
	self.assertEqual(${0}, ${1})
# test function/method
snippet test
	def test_${1:description}(${2:`indent('.') ? 'self' : ''`}):
		${0}
# test case
snippet testcase
	class ${1:ExampleCase}(unittest.TestCase):

		def test_${2:description}(self):
			${0}
snippet fut
	from __future__ import ${0}
#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}])

	except getopt.GetoptError, err:
		# Print debug info
		print str(err)
		${3:error_action}

	for option, argument in opts:
		if option in ("-h", "--help"):
			${0}
		elif option in ("-v", "--verbose"):
			verbose = argument
# logging
# glog = get log
snippet glog
	import logging
	logger = logging.getLogger(${0:__name__})
snippet le
	logger.error(${0:msg})
# conflict with lambda=ld, therefor we change into Logger.debuG
snippet lg
	logger.debug(${0:msg})
snippet lw
	logger.warning(${0:msg})
snippet lc
	logger.critical(${0:msg})
snippet li
	logger.info(${0:msg})
snippet epydoc
	"""${1:Description}

	@param ${2:param}: ${3: Description}
	@type  $2: ${4: Type}

	@return: ${5: Description}
	@rtype : ${6: Type}

	@raise e: ${0: Description}
	"""
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})
snippet args
	*args${1:,}${0}
snippet kwargs
	**kwargs${1:,}${0}
snippet akw
	*args, **kwargs${1:,}${0}