1

I have a Python script, say pyscr.py. Let's say this file defines the following function:

def f1() :
    print ('python func executing')

How do I call this function f1 from a Tcl script?

1
  • I don't know the python syntax, but you'd do something like set python_output [exec python -c {import "pyscr.py"; f1}] Commented Jan 20, 2016 at 21:11

1 Answer 1

1

You need to write a Tcl script to define a procedure to execute a Python script, and then call the procedure. Try this:

#! /usr/bin/tclsh
proc call_python {} {
    set output [exec python pyscr.py]
    puts $output
}

call_python
Sign up to request clarification or add additional context in comments.

6 Comments

This only executes the python module. I am not interested in executing the module alone. I am looking for invoking the python function f1 from tcl script
I get the error can't find package tclpython. I tried to install tclpython as apt-get install tclpython , but this says can not find package tclpython
are you using windows?
Tha't why, tclpython only works on windows, you can find the info here: wiki.tcl.tk/5630
so is there something on linux which can serve the purpose
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.