Data Processing in Shell
Susan Sun
Data Person
Python
Documentation:
man python
...
-V , --version
Prints the Python version number of the executable and exits.
python --version
Python 3.5.2
Example: using native Python
which python
/usr/bin/python
To activate a Python interactive session in the terminal:
python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linuxType "help", "copyright", "credits" or
"license" for more information.
>>>
Inside the interactive session, only use Python syntax:
>>> print('hello world')
hello world
To exit the Python session and return to terminal:
>>> exit()
$
Python interactive session:
Alternative:
.py
scriptpython
+ scriptMethod 1
.py
file using a text editor on the command line (e.g. nano, Vim, Emacs)Method 2
.py
file by echo
-ing the Python syntax into the hello_world.py
file, instantiating the Python file in the same step.echo "print('hello world')" > hello_world.py
Sanity check file content:
cat hello_world.py
print('hello world')
Make sure in the same directory as the .py
file:
ls
hello_world.py
Execute .py
file by preceding filename with python
:
python hello_world.py
hello world
Data Processing in Shell