Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Sharad Singla Newsgroups: comp.lang.python Subject: Re: Re-using TCL code from python over network Date: Tue, 29 Mar 2016 04:29:26 -0400 Lines: 106 Message-ID: References: <172d629d-3dc8-4e47-b163-05b4f32a027c@googlegroups.com> <56FA3179.3080005@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de fvCx3C/RYe21H5T0qTgeWQXDPK0VrG5o6i78t8oeRqfQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'rewrite': 0.07; 'subject:code': 0.07; 'cc:addr:python-list': 0.09; 'anymore.': 0.09; 'modules.': 0.09; 'namespace': 0.09; 'none"': 0.09; 'subject:using': 0.09; 'received:209.85.218': 0.10; 'python': 0.10; 'python.': 0.11; 'subject:python': 0.14; 'interpreter': 0.15; '"set': 0.16; '2016': 0.16; 'eval': 0.16; 'evaluating': 0.16; 'in-house.': 0.16; 'invoking': 0.16; 'ops': 0.16; 'proc': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subprocess': 0.16; 'wrote:': 0.16; 'of.': 0.18; 'email addr:gmail.com>': 0.18; 'python?': 0.18; 'shell': 0.18; 'variable': 0.18; 'thanks.': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; "we'd": 0.21; 'correctly.': 0.22; 'exec': 0.22; 'gather': 0.22; 'libraries': 0.22; 'shifting': 0.22; 'skip:$ 20': 0.22; 'tkinter': 0.22; 'cc:no real name:2**0': 0.22; 'bit': 0.23; "python's": 0.23; 'tried': 0.24; 'import': 0.24; 'written': 0.24; 'header:In-Reply-To:1': 0.24; "i've": 0.25; 'example': 0.26; 'installed': 0.26; 'linux': 0.26; 'points': 0.27; 'skip:# 10': 0.27; 'message- id:@mail.gmail.com': 0.27; 'this.': 0.28; "skip:' 10": 0.28; 'interface': 0.29; 'tcl': 0.29; 'launch': 0.29; '(including': 0.30; 'code': 0.30; 'task': 0.30; 'skip:[ 10': 0.31; "i'd": 0.31; 'anyone': 0.32; 'compiled': 0.32; 'useful': 0.33; 'his/her': 0.33; 'suit': 0.33; 'similar': 0.33; "skip:' 20": 0.34; 'worked': 0.34; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'newer': 0.35; 'but': 0.36; 'needed': 0.36; 'received:209.85': 0.36; 'framework': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'experience,': 0.38; "won't": 0.38; 'version': 0.38; 'received:209': 0.38; 'delete': 0.38; 'stuff': 0.38; 'skip:o 20': 0.38; 'skip:- 20': 0.39; 'test': 0.39; 'data': 0.39; 'subject:from': 0.39; 'subject:-': 0.39; 'where': 0.40; 'your': 0.60; 'close': 0.61; 'share': 0.61; 'email addr:gmail.com': 0.62; 'export': 0.63; 'more': 0.63; 'our': 0.64; 'mar': 0.65; '.....': 0.76; 'bridging': 0.84; 'round.': 0.84; 'subject:over': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=wxiLvxy9UXrc4PA5pg20P1HZK4j+dOirc5eHRQngoqg=; b=wBpVr7PnYuuWVLZR4ODVRkepDjUwCVCiakk7H7Zf+MNHjpjMoaGeKrxcI5Utd1/0cT Fr+CIjxthiNJe9Wy/msIEi71xkp43eqnBbMPbVadO2n8ICDi3ukQCCZBCMyy4p93Buoa +gEd5Hv53D/gg5Pnme4F0Kkuo1wmAiJcngk00IL9YY0saahrsuHxIoEs600L4i7aQoVo d8JUfNXKQOKCUb6JamHMgoVQh84mRQM1qPvcLUvxd5AeAYCsTiRFzdHDe2dpV/sgiRHc HGxZudid9wOSux6M8M5TEK4T7Lb5bLffF3/LCeRHbWwDHxVpP22TI4JO2u1lhywwImYT Sv1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=wxiLvxy9UXrc4PA5pg20P1HZK4j+dOirc5eHRQngoqg=; b=ZrnuxxuHZHqe9oTOwtAwLIFPUwjFBd+z3RoF4ozi6Eg82qZ9ZJqEoggTkMYd0CnFOo yLImXPxm0rg//uwr7PxNNE6UH9yWxcxjZeSD8OK6q757RXWqbKbuVO2zUjbiUoCo/MIC nkENlvYXEbJ8EedMi6YZCNCrkdWUfJ5ghiNukKxATEdo63dXd0+29rb9Cn7jWkSssXct o0ivX0cUr/E29F8O2gSywHV94QkvHNctgF8bY2k0HfXI6UrGlcoe7KL0DlBDPkQeCCCL UKgNgaBttMx4SRVlrYX6CZOEaNHJJrLKI5bMsvqs9AEBbFEh0Dai5SdOsKKHQn+e61OZ T/nw== X-Gm-Message-State: AD7BkJJsQ8fn85l93fTVU9jxiBhStN/gXlR5epwwxbZT0ZnOfS3dGGoJYETAd1N/Hd7uahJkIBx28aKs8Z/kPQ== X-Received: by 10.157.38.227 with SMTP id i32mr350055otd.68.1459240167162; Tue, 29 Mar 2016 01:29:27 -0700 (PDT) In-Reply-To: <56FA3179.3080005@gmail.com> X-Mailman-Approved-At: Tue, 29 Mar 2016 05:17:12 -0400 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105967 Thanks. This is more of invoking python code from TCL. I am looking for the other way round. Curious, did you rewrite all your TCL code in python? Regards Sharad On Mar 29, 2016 1:10 PM, "Karim" wrote: > > > On 29/03/2016 07:20, sharad1087@gmail.com wrote: > >> Hi >> >> We've a test automation framework written in TCL (including the automated >> test cases). We are evaluating shifting to Python and have a test framework >> in Python (including the automated test cases). Python provides a lot more >> 3rd party libraries that we'd like to make use of. >> >> We use a pretty old version of TCL (8.4.5, 32 bit). It's on FreeBSD and >> we've compiled it in-house. Compiling it to 64 bit or moving to a newer >> version is a massive task (since we've a lot of libraries - written in C >> and compiled as well as pure tcl). >> >> Also, we are evaluating having this Python infrastructure on Linux >> (CentOS). >> >> I've explored Python's Tkinter but it won't suit our case as it points to >> system installed TCL. I've also explored Python's subprocess (launch an >> interactive TCL shell remotely) and pexpect but none of them worked well >> for me to allow me to use TCL code interactively from Python. >> >> I'd like to gather any ideas/experience around this. If anyone has tried >> a similar stuff before and can share his/her experience, I'd appreciate it. >> >> Regards >> Sharad >> > > You can find below a partial example where I launch a python process from > a tcl program to get data from python > which reads a database. You just have to get and compile tclpython (google > is your best friend) which is a C interface > bridging python and tcl and allow to launch at most 5 python interpreter > processes if I remember correctly. I used it during 4 > years but I now I migrated all the TCL code to python one indeed I don't > need it anymore. But it is useful to do the transition. > > #!/usr/bin/env tclsh8.4 > > lappend auto_path $env(TCLPYTHON_PKG_PATH) > package require tclpython 4.1 > > namespace eval ops { > namespace export initPython > namespace export exitPython > ... > namespace export getDeviceDescription > > .... > } > > proc ops::initPython {} { > # ---------------------------- > # @goal: Create the interpreter process and import python needed modules. > # @arg: > # @return: > # ---------------------------- > variable interpreter > set interpreter [python::interp new] > $interpreter exec {from ops.tcl.pythontcl import to_string, > to_list, to_dict, to_bool} > .... > $interpreter exec "opsdb = None" > $interpreter exec "input_structure = dict()" > } > > proc ops::exitPython {} { > # ---------------------------- > # @goal: Close the interpreter process. > # @arg: > # @return: > # ---------------------------- > variable interpreter > python::interp delete $interpreter > } > > proc ops::getDeviceDescription { libName deviceName } { > # ---------------------------- > # @goal: get > # @arg: > # @return: > # ---------------------------- > variable interpreter > $interpreter exec "d_s = to_string(getDeviceDescription(opsdb, > '$libName', '$deviceName'))" > > eval "set value [$interpreter eval {d_s}]" > return $value > } > > Karim > > >