library: libPyROOT #include "TPython.h"

# TPython

class description - source file - inheritance tree (.pdf)

## class TPython

| Inheritance Chart:

`TPython`

        private:

          static Bool_t Initialize()

        public:

                                  TPython()
                                  TPython(const TPython&)
                                  ~TPython()
                    static Bool_t Bind(TObject* obj, const char* label)
                   static TClass* Class()
          static const TPyReturn& Eval(const char* expr) const
                      static void Exec(const char* cmd)
                  virtual TClass* IsA() const
                         TPython& operator=(const TPython&)
                      static void Prompt()
                     virtual void ShowMembers(TMemberInspector& insp, char* parent)
                     virtual void Streamer(TBuffer& b)
                             void StreamerNVirtual(TBuffer& b)

### Data Members

## Class Description

                              Python interpreter access
                              =========================

     The TPython class allows for access to python objects from CINT. The current
     functionality is only basic: ROOT objects and builtin types can cross the
     boundary between the two interpreters. All other cross-coding is based on
     strings that are run on the python interpreter.

     Example: Accessing the python interpreter from ROOT

     root [0] gSystem->Load( "libPyROOT" );
     (int)0
     root [1] TPython::Exec( "print 1 + 1" );  // write '2' to stdout
     2

     // create a TBrowser on the python side, and transfer it back and forth
     root [2] TBrowser* b = (TBrowser*) Python::Eval( "ROOT.TBrowser()" );
     root [3] TPython::Bind( b, "b" );
     root [4] b == (TBrowser*) TPython::Eval( "b" )
     (int)1

     // builtin variables can cross-over
     root [5] int i = TPython::Eval( "1 + 1" );
     root [6] i
     (int)2

     It is possible to switch between interpreters by calling "TPython::Prompt()"
     on the CINT side, while returning with ^D (EOF). State is preserved between
     successive switches.

Bool_t Initialize()

     Private initialization method: setup the python interpreter and load the
     ROOT module.

void Exec( const char* cmd )

     Execute a python statement (e.g. "import ROOT").

const TPyReturn& Eval( const char* expr )

     Evaluate a python expression (e.g. "ROOT.TBrowser()").

     Caution: do not hold on to the return value: either store it in a builtin
     type (implicit casting will work), or in a pointer to a ROOT object (explicit
     casting is required).

Bool_t Bind( TObject* obj, const char* label )

     Bind a ROOT object with, at the python side, the name "label".

void Prompt()

     Enter an interactive python session (exit with ^D). State is preserved
     between successive calls.

### Inline Functions

                   void ~TPython()
                TClass* Class()
                TClass* IsA() const
                   void ShowMembers(TMemberInspector& insp, char* parent)
                   void Streamer(TBuffer& b)
                   void StreamerNVirtual(TBuffer& b)
                TPython TPython()
                TPython TPython(const TPython&)
               TPython& operator=(const TPython&)

Author: Wim Lavrijsen, Apr 2004
Last update: root/pyroot:$Name: $:$Id: TPython.cxx,v 1.6 2004/11/23 21:45:06 brun Exp $