Sep. 25, 2012

Using the Python Interpreter

Python interpreter

The Python interpreter is usually installed in /usr/local/bin/python on machines
where it is available; 

Putting /usr/local/bin in your Unix shell’s search path makes it possible to
start it by typing the command: python to the shell.

When you start the Python in interactive mode, it prompts for the next command, 
usually three greater-than signs (">>> "). 

The interpreter prints a welcome message stating its version number and a
copyright notice before printing the first prompt, eg:
Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> the_world_is_flat = 1
>>> if the_world_is_flat:
...     print "Be careful not to fall off!"

Python Interactively

When you use Python interactively, it is handy to have some standard commands
executed every time the interpreter is started. 

You can do this by setting an environment variable named PYTHONSTARTUP to the
name of a file containing your start-up commands. 

This is similar to the .profile feature of the Unix shells.

To do that, add this line to your .bashrc file: 
>> export PYTHONSTARTUP=$HOME/.pythonstartup

Create (or modify) the .pythonstartup file and put your python code in there:
import os
os.system('ls -l')
To exit from the Python interactive prompt, we'll hit Ctrl+D (in Linux)
See Pythons official documentation for more information. 

Recommended Python Training – DataCamp

For Python training, our top recommendation is DataCamp.

Datacamp provides online interactive courses that combine interactive coding challenges with videos from top instructors in the field.

Datacamp has beginner to advanced Python training that programmers of all levels benefit from.


Read more about:
Disclosure of Material Connection: Some of the links in the post above are “affiliate links.” This means if you click on the link and purchase the item, I will receive an affiliate commission. Regardless, only recommend products or services that we try personally and believe will add value to our readers.