5/05/2008

Python in Linux (Red Hat)
Chapter 1
Looking through the book "Diveintopython.pdf" I've found example and as I work in Linux Centos - I've decided to try some examples in shell:
after this warning "Whoops! Just typing python gives you the older version of Python −− the one that was installed by default." I've found the python2.4 that was installed on my PC by default and:

~: python2.4

Python 2.4.3 (#1, Mar 14 2007, 18:51:08)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1+1
2
>>> x=2
>>> r=4
>>> x+r
6

-- first tries were successfull)))

Chapter 2

Next my try was to run from examples my favorite odbchelper.py :

python odbchelper.py
/opt/openoffice.org2.0/program/python.bin: can't open file 'odbchelper.py'
(jj)bin% python2.4
Python 2.4.3 (#1, Mar 14 2007, 18:51:08)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk', '/usr/lib/python2.4/lib-dynload', '/usr/lib/python2.4/site-packages', '/usr/lib/python2.4/site-packages/Numeric', '/usr/lib/python2.4/site-packages/PIL', '/usr/lib/python2.4/site-packages/gtk-2.0']
>>> sys.path.append ('/users/jj/home/diveintopython-5.4/diveintopython-5.4/py')
>>> sys.path
['', '/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk', '/usr/lib/python2.4/lib-dynload', '/usr/lib/python2.4/site-packages', '/usr/lib/python2.4/site-packages/Numeric', '/usr/lib/python2.4/site-packages/PIL', '/usr/lib/python2.4/site-packages/gtk-2.0', '/users/yr0476/home/diveintopython-5.4/diveintopython-5.4/py']
>>> import odbchelper
>>> type (odbchelper)

>>> run odbchelper.py
File "", line 1
run odbchelper.py
^
SyntaxError: invalid syntax
>>> python obdchelper.py
File "", line 1
python obdchelper.py
^
SyntaxError: invalid syntax
>>>
(jj)bin% python odbchelper.py
/opt/openoffice.org2.0/program/python.bin: can't open file 'odbchelper.py'

(jj)bin% cd /users/yr0476/home/diveintopython-5.4/diveintopython-5.4/py
(jj)py% python odbchelper.py
pwd=secret;database=master;uid=sa;server=mpilgrim
(jj)py% print odbchelper.buildConnectionString(params)

CORRECT>printf odbchelper.buildConnectionString(params) (y|n|e|a)? no
Badly placed ()'s.
(jj)py% print odbchelper.buildConnectionString ( params )

CORRECT>printf odbchelper.buildConnectionString ( params ) (y|n|e|a)? yes
Badly placed ()'s.
(jj)py% import odbchelper

(jj)
py% python2.4
Python 2.4.3 (#1, Mar 14 2007, 18:51:08)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import odbchelper
>>> import odbchelper
>>> params = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"}
>>> print odbchelper.buildConnectionString(params)
pwd=secret;database=master;uid=sa;server=mpilgrim
>>> print odbchelper.buildConnectionString.__doc__
Build a connection string from a dictionary

Returns string.

-- so this was successful too _)))


Немає коментарів: