Справка:Разметка Python-текстов
Материал из PythonWiki.
Содержание |
[править]
Пайтон
[править]
Hello, world
>>> a = range(1,10000000) >>> del a class c: def p(self, x): return x def fun(x): print x >>> fun("Hello, %s" % c().p("world"))
[править]
Контролер TurboGears навигатора LDAP каталогов
import logging import cherrypy import turbogears from turbogears import controllers, expose, validate, redirect from ldapnav import json import ldap log = logging.getLogger("ldapnav.controllers") class Root(controllers.RootController): """Контролер для навігатора LDAP каталогів """ login_dn = "domain\\user" login_pw = 'password' host = "192.168.1.6" def __connect(self): l = ldap.open(self.host) l.simple_bind_s(self.login_dn, self.login_pw) return l def __disconnect(self, conn): conn.unbind() @expose(template="ldapnav.templates.index") def index(self): return self.go() @expose(template="ldapnav.templates.index") def go(self, entry="OU=Unit, DC=company, DC=com"): def stackLinks(prevLink, remPath): """Builds a list of linkName,linkHref tuples corresponding to the elements in the path tree. """ ## Рекурсивно проходить весь список if len(remPath)>1: item = remPath.pop() currentName = (item.split('=',2))[1] item = remPath.pop() currentName = (item.split('=',2))[1] currentLink = item + prevLink return ([[currentName, currentLink]] + stackLinks(',' + currentLink, remPath)) else: item = remPath.pop() currentName = (item.split('=',2))[1] currentLink = item + prevLink return [[currentName, currentLink]] pass conn = self.__connect() res = conn.search_s(entry, ldap.SCOPE_ONELEVEL, "objectclass=*",) current = (conn.search_s(entry, ldap.SCOPE_BASE, "objectclass=*",))[0] self.__disconnect(conn) pathToCurrent = ldap.explode_dn(current[0]) pathToCurrentLinks = stackLinks('', pathToCurrent) return dict(entries=res, currentDN=current, pathDN=pathToCurrentLinks)
[править]
Perl
a = $@
[править]
Eiffel
class root inherit god creation make feature make is do print("Hello, world!") end end
[править]
Java
/** Java class with errors. * * @author vityok */ public class HelloWorld { public static void main(String[] args) { System.stdout.println("Hello world"); } }

