You are here: Home Plone Python Basics Basics
Search
Advanced Search…
E-Mail

Webmail: webmail.wyden.com

E-Mail Preferences: postfix.wyden.com/users

E-Mail Administration: postfix.wyden.com

Statistics
Total: 463
Total Pages: 284
Total Folders: 87
Total Files: 18
Total Links: 26
Last modification: 03.02.2012 16:00
 

Basics

by Wyden Silvan last modified 26.11.2009 13:43

#integer to string
str(int)

#buil-in attributest
__doc__ -> gibt alle Kommentare zurück
__name__ -> gibt den Namen zurück vom File

#Funktion
def  FUNKTION(param1,params2):

#alles sind Objekte
import odbchelper
params = {"server":"mpilgrim", "database":"master"}
print odbchelper.buildConnectionString(params)
print odbchelper.buildConnectionsString.__doc__

#Seach Path
import sys
sys.path
sys
sys.path.append('/my/new/path')

#Dictionary key:value
d={"server":"mpilgrim", "database":"master"};
d -> {'server': 'mpilgrim', 'databse': 'master'}
d["server"] -> 'mpilgrim'
d["database"] = "pubs" -> value und nicht key wird ersetzt
d["uid"] = 55 -> uid:55 wird hinzugefügt
d[20:'abcd']
del d['master]
d.clear() -> löscht gesamten Inhalt

#Lists
li = ["a", "b", "c"]
li -> ['a', 'b', 'c']
li[0] -> 'a'
li[-1] -> 'c' -> returns the last elemen -> counts backward
li[0:2] -> gibt 1. + 2. element ohne (letzes)
li.append("new") -> fügt Element am Ende hinzu
li.insert(2, "new") ->
li.extend(LIST) -> li.extend(["two", "elements"]) -> fügt Element auch am Ende hinzu
li.append(LIST) -> fügt eine Liste in eine LIste ein
li.index("a") -> sucht nach a in der liste
"a" in li -> gibt true oder false zurück ob Element in Liste oder nicht
li.remove("a") -> löscht nur das 1. Element, das "a" ist
li.pop() -> löscht das letzte Element und gibt dessen Wert zurück
li = li + ['d','e'] -> oder li += [...

#tuple = an immutable list -> can not be changed in any way once it is created
t = ("a", "b", "mpilgram", "z", "example")
-> same functions like a list, but no methods

#variables
%s = placeholoder for strings
%d = placeholoder for integers
%f = float
k = "uid"
v = "sa"
"%s=%s" % (k, v) -> 'uid=sa'
print "today's stock price: %f" % 50.1625

#strings
code.isalpha()