Skip to content

Instantly share code, notes, and snippets.

View kennethlove's full-sized avatar
🦀
Python

Kenneth Love kennethlove

🦀
Python
View GitHub Profile

Defining Functions in Python

(this is all assumed to be done in the shell)

Before we start, we need to get into our Python shell. Once you open up your terminal program of choice, you'll want to type python. You should now see some information about the version of Python you're running and three greater-than symbols. If you have IPython installed, feel free to use that instead.

In programming, a "function" or "method" is often the name we give to blocks of code that the computer can repeat for us. In our human world, this would be like us going through the same sets of folds for all of the napkins at a wedding reception.

In Python, these stand-alone, repeatable code blocks are called "functions" and we create new ones with the def keyword. Function names have to start with an underscore or a letter and can't contain spaces or hyphens. We'll call this function "hello". Function definitions always end with an open parenthesis. We'll talk about passing arguments to functions

class FooMixin(object):
def get_formset(self, request, obj=None, **kwargs):
form = self.form
form.fields['butts'].queryset = Butts.objects.filter(oily=True)
kwargs.update({'form': form})
return super(FooMixin, self).get_formset(request, obj=obj, kwargs)
def index(request):
if request.method == "GET":
return render_to_response('locations/index.html', {'nosearch': True})
elif request.method == "POST":
context = {}
result = Location.objects.filter(address=request.POST['address'])
loc = result.first()
context['loc'] = loc
context['services'] = _get_services(loc)
return render_to_response('locations/services.html', context)
[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]](([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[+[]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]+(!![]+[
@kennethlove
kennethlove / draft
Created October 8, 2013 05:57
draft outline
# Hello!
## Getting Started with Django
Go from apprentice to journeyman
## Lincoln Loop
### Django Round-Up
Podcasts can be educational too
# Learning 4 lyfe
More than anything, though, I'm a learner.
@kennethlove
kennethlove / base.html
Last active December 21, 2015 15:09
PyLadies templates ~#27
<!doctype html>
<html>
<head>
<title>{% block page_title %}My Blog{% endblock %}</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.2.0/pure-min.css">
<link rel="stylesheet" href="{{ STATIC_URL }}css/pyladies.css">
</head>
<body>
<div class="pure-g-r layout">
<div class="pure-u sidebar">

Lincoln Loop is looking for a web generalist to join our ranks. We have lots of domain experts, but need someone who can tie up the loose ends. A strong knowledge of CSS and HTML is required along with a working knowledge of JavaScript and Python. You should have a year or so of experience building clean cross-browser interfaces and be familiar with responsive design techniques for mobile.

Bonus points for experience/knowledge in:

  • CSS Preprocessors (SASS or LESS)
  • Django
  • Backbone or similar JS framework
  • Visual design

We're a fully distributed company where everyone sets their own hours and salary. You can learn more about how we operate at http://lincolnloop.com/blog/categories/business/. This is a full-time position.

[tox]
envlist = py2.6-d1.3, py2.7-d1.3, py2.6-d1.4, py2.7-d1.4, py2.7-d1.5, py3.3-d1.5, py3.3-d1.6, py2.7-d1.6
[testenv]
commands =
py.test tests/
deps =
mock
pytest-django
Dear Kenneth Love,
After running by your project Getting Started With Django we strongly believe there is definitely a synergy opportunity in store for both of us. You’ve got an awesome project, while we have an unprecedented SEO platform that is designed for the client to pay only if we drive substantial results. We’re the only ones in the world to offer the total opposite of what any other SEO company does, and all of our campaigns are 100% refundable if we don’t achieve results. In fact, we have vast experience in your niche and know exactly how to accomplish results. We want to demonstrate this to you – that's why we’ve taken the liberty to contact you.
Can you contact us via e-mail at [email protected] or through our toll-free +1 (800) SEO-XXXX number? We’re extremely interested in doing some comprehensive SEO work on your website. Your project is incredible! Pursuant to our preliminary assessment, it’s the best time to propel your current website given your success through crowd funding.
@kennethlove
kennethlove / gist:5725610
Created June 6, 2013 22:45
Find quotes that don't start with a 'u'
regex = ur'(\s|\=|\(|\[|\{)[u]{0}(\'|\")(?!\"\")(?!\'\')'