Chapter 1. General introduction

Table of Contents

1.1. Running Python
1.2. Documentation
1.2.1. General informations
1.2.2. Getting information
1.2.3. Making documentation
1.3. Working environment
1.3.1. Emacs

1.1. Running Python

There are several ways to run Python code:

  1. from the interpreter:

    >>> dna = 'gcatgacgttattacgactctgtcacgccgcggtgcgactgaggcgtggcgtctgctggg'
    >>> dna
    'gcatgacgttattacgactctgtcacgccgcggtgcgactgaggcgtggcgtctgctggg'
    	    
  2. from a file:

    If file mydna.py contains:

    #! /local/bin/python
    
    dna = 'gcatgacgttattacgactctgtcacgccgcggtgcgactgaggcgtggcgtctgctggg'
    print dna
    	      
    it can be executed from the command line:
    caroline:~> python mydna.py 
    gcatgacgttattacgactctgtcacgccgcggtgcgactgaggcgtggcgtctgctggg
    	      
    or using the #! notation:
    caroline:~> ./mydna.py 
    gcatgacgttattacgactctgtcacgccgcggtgcgactgaggcgtggcgtctgctggg
    	      

    It is also possible to execute files during an interactive interpreter session:

    caroline:~> python
    Python 2.2.1c1 (#1, Mar 27 2002, 13:20:02) 
    [GCC 2.95.4  (Debian prerelease)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> execfile('mydna.py')
    gcatgacgttattacgactctgtcacgccgcggtgcgactgaggcgtggcgtctgctggg
    	      

    or to load a file from the command line before entering Python in interactive mode (-i):

    caroline:~> python -i mydna.py
    gcatgacgttattacgactctgtcacgccgcggtgcgactgaggcgtggcgtctgctggg
    >>> 
    	      
    this is very convenient when your Python file contains definitions (functions, classes,...) that you want to test interactively.

  3. from other programs embedding the Python interpreter:

    #include <Python.h>
    
    int main(int argc, char** argv) {
    
      Py_Initialize();
      PyRun_SimpleString("dna = 'atgagag' + 'tagagga'");
      PyRun_SimpleString("print 'Dna is:', dna");
    
      return 0;
    }