Collection of Snippets for Python

The Python snippets are inspired by Gedit.

Just copy the [Special] and [Python] sections from the code below into your snippets file, e.g. in ~/.config/geany/snippets.conf.

[Special]
wordchars=._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
 
[Python]
for=for i in xrange(%cursor%):\n\t
doc=""" %cursor% """\n
elif=elif %cursor%:\n\t
else=else:\n\t%cursor%
if=if %cursor%:\n\t
from=from %cursor% import \n
main=if __name__ == '__main__':\n\t%cursor%
class=class %cursor%(object):\n\t""" Class doc """\n\t\n\tdef __init__ (self):\n\t\t""" Class initialiser """\n\t\tpass
def=def %cursor%(self):\n\t""" Function doc\n\n\t@param PARAM: DESCRIPTION\n\t@return RETURN: DESCRIPTION\n\t"""\n\t
get=def get%cursor%(self): return self._var\n
set=def set%cursor%(self): self._var = var\n
.=self.%cursor%
prop=property %cursor%:\n\tdef __get__(self):\n\t\treturn self.%cursor%_get()\n\n\tdef __set__(self, value):\n\t\tself.%cursor%_set(value)
try=try:\n\t%cursor%\nexcept Exception, e:\n\t
py=#!/usr/bin/env python\n#-*- coding:utf-8 -*-\n\n%cursor%
while=while %cursor%:\n\t
with=with %cursor%:\n\t
head="""\n\t%cursor%PROJECT - MODULE\n\n\tDESCRIPTION\n\n\t@copyright: {year} by {developer} <{mail}>\n\t@license: GNU GPL, see COPYING for details.\n"""\n
pp=from pprint import pprint\npprint(%cursor%)
cod=# coding: utf-8
dt=from datetime import datetime

Alternative

Modified Specifically for Python3 and PEP8-compliant

[Python]
utf8=#-*- coding: utf-8 -*-\n# vim:fileencoding=utf-8
for=for i in xrange(%cursor%):\n\t
doc=""" %cursor% """\n
elif=elif %cursor%:\n\t
else=else:\n\t%cursor%
if=if %cursor%:\n\t
from=from %cursor% import \n
main=if __name__ == '__main__':\n\t%cursor%
class=class %cursor%(object):\n\t""" Class doc """\n\t\n\tdef __init__ (self):\n\t\t""" Class initialiser """\n\t\tpass
def=def %cursor%(ARG: TYPE) -> TYPE:\n\t"""DOC"""\n\t
get=def get%cursor%(self): return self._var\n
set=def set%cursor%(self): self._var = var\n
try=try:\n\t%cursor%\nexcept Exception, e:\n\t
py=#!/usr/bin/env python3\n#-*- coding:utf-8 -*-\n# vim:fileencoding=utf-8\n
while=while %cursor%:\n\t
with=with %cursor%:\n\t
head="""\n\t%cursor%PROJECT - MODULE\n\n\tDESCRIPTION\n\n\t@copyright: {year} by {developer} <{mail}>\n\t@license: GNU GPL, see COPYING for details.\n"""\n
# Django models
# by Tomasz Karbownicki <tomasz@karbownicki.com>
mclass=class %cursor%(models.Model):\n\t'''%cursor%'''\n\n\tdef __unicode__(self):\n\t\treturn self.XXXXX\n\n\tdef get_absolute_url(self):\n\t\treturn "/XXXXX/%s/" % self.slug\n\n\tclass Meta:\n\t\tverbose_name = "%cursor%"\n\t\tverbose_name_plural = "%cursor%"
mchar=%cursor% = models.CharField(max_length=50, verbose_name=u'%cursor%')
mint=%cursor% = models.IntegerField(verbose_name=u'%cursor%')
mtext=%cursor% = models.TextField(verbose_name=u'%cursor%')
mkey=%cursor% = models.ForeignKey(%cursor%, verbose_name=u'%cursor%')
mimage=%cursor% = models.ImageField(upload_to='', verbose_name=u'%cursor%')
mbool=%cursor% = models.BooleanField(verbose_name=u'%cursor%')
mdate=%cursor% = models.DateField(verbose_name=u'%cursor%', help_text='Format daty: 2009-04-28')
memail=%cursor% = models.EmailField(verbose_name=u'%cursor%')
murl=%cursor% = models.URLField(verbose_name=u'%cursor%')
mslug=%cursor% = models.SlugField(verbose_name=u'%cursor%', unique=True)
# by Devyn Collier Johnson <DevynCJohnson@Gmail.com>
license=__license__ = """LGPLv3\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU Lesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public License\nalong with this program.  If not, see <http://www.gnu.org/licenses/>.\n"""
all=__all__ = [\n\t'FUNC',\n]
debug=print('HERE')  # DEBUG: Print
Print/export