Assumptions and notes:
python
is aliased to
/usr/local/bin/python
somefile
contains this python code:
i = 3 print i
.py
on python program,
but this is not required. It is required if you want
the code to be a module that can be imported into other python programs
and scripts.
There are several ways to execute a python program:
rucs @ /home/nokie > python Python 1.5.1 (#1, Nov 29 1999, 14:33:24) [GCC 2.8.1] on sunos5 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> i = 5 >>> print i 5 >>> ^D rucs @ /home/nokie >
rucs @ /home/nokie > python somefile 3 rucs @ /home/nokie >
rucs @ /home/nokie> python Python 1.5.1 (#1, Nov 29 1999, 14:33:24) [GCC 2.8.1] on sunos5 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> execfile("somefile") 3
rucs @ /home/nokie > python -i somefile 3 >>> print i+1 4 >>>
#!/usr/bin/python
afile
(starting in column 1),
make afile
executable,
and run afile
as a script:
rucs @ /home/nokie > cat afile #!/usr/local/bin/pythonTo find the current location of python, enter#!/usr/local/bin/pythonprint "This is a script" rucs @ /home/nokie > chmod 700 afile rucs @ /home/nokie > afile This is a script rucs @ /home/nokie >
which python