�n�߂悤
Python�̒���
- �I�u�W�F�N�g�w�� (OOP)
like ... Smalltalk, C++, Java
- �I�[�v���E�\�[�X
�t���[��������Ȃ��C�J���ɎQ���ł���
- �ڐA��
- ����
- �������ꉻ�\
C, C++ �ŏ��������i�ƌ����ł���
- �g���₷��
�C���^�v���^�E�X�N���v�g����
���Ԍ���(�o�C�g�R�[�h)
Python�̗p�r
- �V�X�e���E���[�e�B���e�B
- GUI
- �v���g�^�C�s���O
- �C���^�[�l�b�g�E�X�N���v�g (CGI)
- ���l�v�Z
- �f�[�^�x�[�X
Python�Ɨގ��c�[��
Python �v���O�����̎��s
�p�X�̐ݒ�
���̃A�v���P�[�V�����ł��ꏏ�����C�R�}���h���C���X�g�[�����Ă����Ă�
�p�X���ʂ��Ă��Ȃ��Ǝg���Ȃ��D
% which python
no python in /usr/bin /bin /usr/openwin/bin
% set path = (/pub/solaris/python/bin $path)
% which python
/pub/solaris/python/bin/python
% python
[GCC 2.8.1] on sunos5
Type "copyright", "credits" or "license" for more information.
>>>
�Θb�I��(�C���^���N�e�B�u)
% python
>>> print 'Hello world!'
Hello world!
>>> 35 + 65
100
>>> x = 35
>>> y = 65
>>> print x + y
100
>>> (Ctrl+D) or (Ctrl+Z) �I��
���W���[���t�@�C���̎��s
% cat > spam.py
import sys
print sys.argv
(Ctrl+D)
�܂��́C�e�L�X�g�G�f�B�^��vi�Ȃǂō쐬���Ă��悢�D
% python spam.py -i eggs -o bacon
['spam.py', '-i', 'eggs', '-o', 'bacon']
�X�N���v�g�̍쐬�Ǝ��s
- �ŏ��̍s������(�ȃR�����g)
#! �Ŏn�܂�
- ���s�\�p�[�~�b�V����
chmod +x ...
% cat > brian
#!/pub/solaris/python/bin/python
print 'The Bright Side of Life ...'
(Ctrl+D)
�܂��́C�e�L�X�g�G�f�B�^��vi�Ȃǂō쐬���Ă��悢�D
% chmod +x brian
% brian
The Bright Side of Life ...
Python �� �s�̒��� # �������ƁC����������R�����g�Ƃ݂Ȃ��̂ŁC
python brian �ł������悤�Ɏ��s�ł���D
�܂��C�ŏ��̍s�� #!/usr/bin/env python �ł��悢�D
���W���[���t�@�C���ɂ���
���W���[���� import �ł���D
% cat > myfile.py
title = "The Meaning of Life"
(Ctrl+D)
�܂��́C�e�L�X�g�G�f�B�^��vi�Ȃǂō쐬���Ă��悢�D
% python
>>> import myfile
>>> print myfile.title
The Meaning of Life
���邢�́C
% python
>>> from myfile import title
>>> print title
The Meaning of Life
���O���
dir ��
Python �̊��ݒ�
C�V�F���� path �ϐ���ݒ�D(�܂��� ���ϐ� PATH ��ݒ�)
~/.cshrc �� path ��ݒ肵�Ă���Ƃ��낪����̂ŁC/pub/solaris/python/bin ��
�t�������������D
�V�X�e���ɂ���Ă͋��ȏ��̂悤�� setenv ���K�v��������Ȃ��D
GUI�e�X�g
% python
>>> from Tkinter import *
>>> w = Button(text='Hello', command='exit')
>>> w.pack()
>>> w.mainloop()
���K���
- �Θb�I�� Python �R�}���h�����s���Ă݂悤�D�K���ȕ������ print �ƁC
�P���Ȍv�Z�C�ϐ����g�����v�Z�� print �������Ă݂悤�D
- �e�L�X�g�G�f�B�^��p���āC��Ŏ��������Ƃ��s�Ȃ��C�ȒP�ȃ��W���[��
�t�@�C�����쐬���Ȃ����D���̃t�@�C�����V�F���̃R�}���h���C������
python �̈����Ƃ��ė^���Ď��s���Ă݂Ȃ����D
- Python ��Θb�I�ɋN������̃��W���[���� import ���Ȃ����D
- �쐬�������W���[���̍ŏ��̍s�� #! �Ŏn�܂�s�����C�t�@�C����
���s����t���邱�Ƃɂ���āC�V�F���̃R�}���h���C�����璼��
�X�N���v�g�t�@�C�����Ăяo���Ď��s���Ȃ����D
- 1 / 0 �����s����ƁC�ǂ��Ȃ邾�낤���H