1
Začínáme
% python
>>> print 'Hello world!'
Hello world!
>>> lumberjack = "okay"
>>> import sys
print sys.argv % python spam.py –i eggs –o bacon
['spam.py', '-i', 'eggs', '-o', 'bacon']
C:\Python> python spam.py -i eggs -o bacon
['spam.py', '-i', 'eggs', '-o', 'bacon']
print 'The Bright Side of Life...'
% brian
The Bright Side of Life...
C:\Python> python brian
The Bright Side of Life...
...
Py_Initialize();
PyRun_SimpleString(”x = brave + sir + robin”);
% python
>>> print x
print x
% brian
% python spam.py
title = ”The Meaning of Life”
% python
>>> import myfile >>> print myfile.title The Meaning of Life
% python
>>> from myfile import title >>> print title The Meaning of Life
% python
>>> import myfile >>> print myfile.title The Meaning of Life
>>> import myfile >>> reload(myfile) >>> x = 1
>>> y = "shrubbery"
>>> dir()
['__builtins__', '__doc__', '__name__', 'x', 'y']
% cat threenames.py
a = 'dead'
b = 'parrot'
c = 'sketch'
% python
>>> import threenames
>>> dir(threenames)
['__builtins__', '__doc__', '__file__', '__name__', 'a', 'b', 'c']
>>> dir(__builtins__)
setenv PYTHONPATH \
.:/usr/local/lib/python:/usr/local/lib/python/tkinter
export PYTHONPATH=\
”.:/usr/local/lib/python:/usr/local/lib/python/tkinter”
set PYTHONPATH=.;C:\Python\lib;C:\Python\lib\tkinter
set path = (/usr/local/bin $path)
setenv PYTHONPATH \
.:/usr/local/lib/python:/usr/local/lib/python/tkinter
setenv TCL_LIBRARY /usr/local/lib/tcl8.0
setenv TK_LIBRARY /usr/local/lib/tk8.0
python
PATH C:\Python;%PATH%
set PYTHONPATH=.;C:\Python\lib;C:\Python\lib\tkinter
set TCL_LIBRARY=C:\Program Files\Tcl\lib\tcl8.0
set TK_LIBRARY=C:\Program Files\Tcl\lib\tk8.0
python
% runpy
>>> from Tkinter import *
>>> w = Button(text="Hello", command='exit')
>>> w.pack()
>>> w.mainloop()
% python
>>> L = [1, 2]
>>> L.append(L)
>>> L