Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Attaching to a Python Interpreter a la Tcl

Reply
Thread Tools

Attaching to a Python Interpreter a la Tcl

 
 
DE
Guest
Posts: n/a
 
      02-23-2005
Hello,

Some long time ago, I used to use Tcl/Tk. I had an tcl embedded into my
app.

The coolest thing was however, I was able to attach to the interpreter
(built in to my app) via a tcl shell in which I could type in regular
tcl code which would be interpreted by the interpreter of my
application. Naturally, it was possible to call tcl functions of my
applications.

Some kind of rapid RPC.

Is this also possible with python ?

Thanks,

 
Reply With Quote
 
 
 
 
Robin Becker
Guest
Posts: n/a
 
      02-23-2005
DE wrote:
> Hello,
>
> Some long time ago, I used to use Tcl/Tk. I had an tcl embedded into my
> app.
>
> The coolest thing was however, I was able to attach to the interpreter
> (built in to my app) via a tcl shell in which I could type in regular
> tcl code which would be interpreted by the interpreter of my
> application. Naturally, it was possible to call tcl functions of my
> applications.
>
> Some kind of rapid RPC.
>
> Is this also possible with python ?
>
> Thanks,
>

I think you are talking about the tk send command which allows for
communicating with a known app.

I don't believe python comes with such a facility without some coding,
but it has been implemented in various ways using sockets etc etc.

I seem to remember that modern idle uses an rpc technique for debugging.

There are several python projects which address interprocess
communication pyro http://pyro.sourceforge.net/ is a good example.
--
Robin Becker
 
Reply With Quote
 
 
 
 
Fuzzyman
Guest
Posts: n/a
 
      02-23-2005
Do you mean making the interpreter available from within a Python app ?

There are various ways of doing that - you can see the SPE editor which
uses pycrust as one example. http://spe.pycs.net

You could also embed IPython for a good interface to the interpreter.
http://ipython.scipy.net

Regards,


Fuzzy
http://www.voidspace.org.uk/python/index.shtml

 
Reply With Quote
 
Ville Vainio
Guest
Posts: n/a
 
      02-23-2005
>>>>> "fuzzyman" == Fuzzyman <> writes:

fuzzyman> Do you mean making the interpreter available from within
fuzzyman> a Python app ? There are various ways of doing that -
fuzzyman> you can see the SPE editor which uses pycrust as one
fuzzyman> example. http://spe.pycs.net

I believe he means embedding he interpreter in his app, then accessing
the interpreter from another process - so you could change and view
global vars of the running process from the interpreter, for
example. This basically means redirecting i/o of the interpreter to a
socket to which you connect via, say, telnet. There are libs that do
such a thing, I even remember trying one out myself, but I couldn't
find it quickly enough from google.

--
Ville Vainio http://tinyurl.com/2prnb
 
Reply With Quote
 
Cameron Laird
Guest
Posts: n/a
 
      02-24-2005
In article <>,
Robin Becker <> wrote:
>DE wrote:
>> Hello,
>>
>> Some long time ago, I used to use Tcl/Tk. I had an tcl embedded into my
>> app.
>>
>> The coolest thing was however, I was able to attach to the interpreter
>> (built in to my app) via a tcl shell in which I could type in regular
>> tcl code which would be interpreted by the interpreter of my
>> application. Naturally, it was possible to call tcl functions of my
>> applications.
>>
>> Some kind of rapid RPC.
>>
>> Is this also possible with python ?
>>
>> Thanks,
>>

>I think you are talking about the tk send command which allows for
>communicating with a known app.
>
>I don't believe python comes with such a facility without some coding,
>but it has been implemented in various ways using sockets etc etc.
>
>I seem to remember that modern idle uses an rpc technique for debugging.
>
>There are several python projects which address interprocess
>communication pyro http://pyro.sourceforge.net/ is a good example.

.
.
.
Agreed: Python makes it easy to do this. Tk *does* this,
out-of-the-box.

But note! Tkinter can access Tk's [send], so, if the appli-
cation happened to be built with Tkinter, and one were fluent
enough at translating between Tcl and Python to reach the
latter by way of the former, then, yes, you would find that
your Python application already has this.
 
Reply With Quote
 
Stephen Thorne
Guest
Posts: n/a
 
      02-24-2005
On 23 Feb 2005 02:37:48 -0800, DE <> wrote:
> Hello,
>
> Some long time ago, I used to use Tcl/Tk. I had an tcl embedded into my
> app.
>
> The coolest thing was however, I was able to attach to the interpreter
> (built in to my app) via a tcl shell in which I could type in regular
> tcl code which would be interpreted by the interpreter of my
> application. Naturally, it was possible to call tcl functions of my
> applications.
>
> Some kind of rapid RPC.
>
> Is this also possible with python ?


Yes, using something like twisted's 'Manhole', which allows you to
execute code in the server process.

It may require twisted-ising your application however.

Stephen
 
Reply With Quote
 
Jeff Epler
Guest
Posts: n/a
 
      02-24-2005
Cameron Laird mentioned Tk's send working with Python; if you are writing your
app with Tkinter, here is some code to let you use tcl commands like
send <appname> python <expression or statement>
for remote control. You could build a more sophisticated front-end for this,
and you'll probably also want to add stuff like sending the text of an
exception as the result of the 'send' command.

Jeff

#------------------------------------------------------------------------
import Tkinter

__all__ = 'python', 'setup_send'
def makecommand(master, name, func, subst=None, needcleanup=0):
f = Tkinter.CallWrapper(func, subst, master).__call__
master.tk.createcommand(name, f)
if needcleanup:
if master._tclCommands is None:
master._tclCommands = []
master._tclCommands.append(name)
return name


def setup_send(app, ns, name="python"):
def python(*args):
s = " ".join(args)
print args
try:
code = compile(s, '<send>', 'eval')
return eval(code, ns)
except SyntaxError:
code = compile(s, '<send>', 'exec')
exec code in ns
makecommand(app, name, python)

if __name__ == '__main__':
app = Tkinter.Tk()
setup_send(app, {})
app.mainloop()
#------------------------------------------------------------------------

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFCHdt7Jd01MZaTXX0RAp0dAKCbVF88J7nEo4Nyg+F06x D5uZhrPgCeIwyz
HepI83ocgSrW+EoRD/BQ8Vc=
=vBV2
-----END PGP SIGNATURE-----

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to build a loadable tcl dll with visual studio (microsoft C compiler)?[crosspost in comp.lang.tcl and comp.lang.c++] Michael Reichenbach C++ 5 02-08-2010 02:38 PM
Attaching a live interpreter to a script? Kannon Python 0 01-13-2009 07:35 AM
Python embedded interpreter: how to initialize the interpreter ? ycollet@freesurf.fr Python 3 01-03-2007 01:00 AM
Inline::Tcl vs. Inline::Tcl Mumia W. Perl Misc 0 08-23-2006 04:09 PM
Compile problem with TCL interpreter David Swedish C++ 1 02-06-2004 07:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57