简体   繁体   English

如何从Tcl脚本调用Python函数

[英]How to call a Python function from a Tcl script

I have a Python script, say pyscr.py . 我有一个Python脚本,例如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? 如何从Tcl脚本中调用此函数f1

You need to write a Tcl script to define a procedure to execute a Python script, and then call the procedure. 您需要编写一个Tcl脚本来定义执行Python脚本的过程,然后调用该过程。 Try this: 尝试这个:

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

call_python

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM