Quantcast
Channel: Basics Category Page - PythonForBeginners.com
Viewing all articles
Browse latest Browse all 193

Using the Python Interpreter

$
0
0

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 startit 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 nameof 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. 

The post Using the Python Interpreter appeared first on Python For Beginners.


Viewing all articles
Browse latest Browse all 193

Trending Articles