On Github nagyv / szegedtech-februar2012
#!/usr/bin/env python # -*- coding: UTF-8 -*- # Egy minta def hello(): print 'Hello Világ' class Hello(object): '''Ez az osztály köszön neked''' def __init__(self, name): self.name = name def sayIt(self): print 'Hello %s!' % self.name mindenkinek = Hello('mindenkinek') mindenkinek.sayIt()Compared to C, Python programs are much shorter, and consequently much faster to write. In comparison with Perl, Python code is easier to read, write and maintain. Relative to TCL, Python is better suited for larger or more complicated programs. Guido van Rossum 80-as évek vége, 90-es évek eleje általános programnyelv
import this
import os mypath = os.path.join(__file__, '..', 'valami') if mypath: print mypath try: open(mypath, 'r') except IOError, e: print 'hiba' odd = filter(lambda x: x%2, range(10)) def generated(x): yield x mygen = generated(range(10))
2.6, 2.7 vagy 3.1?
#!/usr/bin/env python # usage: fab staging deploy from __future__ import with_statement from fabric.api import local, settings, abort, run, cd, env, sudo from fabric.contrib.console import confirm # ... def deploy(): """Updates the server and restarts it""" clone_repo_if_needed() with cd(env.project_root): run_with_failure('git pull --all', 'Updating all repos failed.') run_with_failure('git checkout %s' % env.branch, 'Updating %s branch failed.' % env.branch) run_with_failure('git pull', 'Git pull failed.') #update submodules run("git submodule init") run("git submodule update") if env.just_cloned: create_virtualenv() run_with_failure(env.activate + "pip install -r requirements.txt", 'Installing requirements failed.') run_with_failure(env.activate + "python manage.py syncdb --migrate --noinput", "Syncdb failed.") run_with_failure(env.activate + "python manage.py collectstatic --noinput", "Collectstatic failed.") run("touch wsgi/staging.py")