Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
snippets:python:start [2011/06/13 17:07] – lowercase tags enricosnippets:python:start [2015/11/29 14:10] – Tweaked code highlighting devyncjohnson
Line 3: Line 3:
 The Python snippets are inspired by Gedit.  The Python snippets are inspired by Gedit. 
  
-Just copy the the [Special] and [Python] sections from the code below.+Just copy the the [Special] and [Python] sections from the code below into your snippets file, e.g. in //~/.config/geany/snippets.conf//.
  
  
-<code>+<code properties>
 [Special] [Special]
 wordchars=._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 wordchars=._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
Line 23: Line 23:
 set=def set%cursor%(self): self._var = var\n set=def set%cursor%(self): self._var = var\n
 .=self.%cursor% .=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 try=try:\n\t%cursor%\nexcept Exception, e:\n\t
 py=#!/usr/bin/env python\n#-*- coding:utf-8 -*-\n\n%cursor% py=#!/usr/bin/env python\n#-*- coding:utf-8 -*-\n\n%cursor%
Line 28: Line 29:
 with=with %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 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
 </code> </code>
 +
 +===== Alternative =====
 +
 +Modified Specifically for Python3 and PEP8-compliant
 +
 +<code properties>[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</code>
 +
  
 {{tag>snippet python}} {{tag>snippet python}}
Print/export