Table of Contents
There are several ways to run Python code:
from the interpreter:
>>> dna = 'gcatgacgttattacgactctgtcacgccgcggtgcgactgaggcgtggcgtctgctggg' >>> dna 'gcatgacgttattacgactctgtcacgccgcggtgcgactgaggcgtggcgtctgctggg'
from a file:
If file mydna.py contains:
#! /local/bin/python dna = 'gcatgacgttattacgactctgtcacgccgcggtgcgactgaggcgtggcgtctgctggg' print dnait can be executed from the command line:
caroline:~> python mydna.py gcatgacgttattacgactctgtcacgccgcggtgcgactgaggcgtggcgtctgctgggor 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.
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;
}