Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从python脚本向makefile变量返回一个值_Python_Python 3.x_Python 2.7_Makefile - Fatal编程技术网

从python脚本向makefile变量返回一个值

从python脚本向makefile变量返回一个值,python,python-3.x,python-2.7,makefile,Python,Python 3.x,Python 2.7,Makefile,我需要通过makefile运行python脚本。Python脚本执行一些计算并返回一个值。我想在makefile变量中获取该值。我怎么能做到 我想要这样的东西: mymakefile.mke $output = python process.py process.py import os def main(): value = "01.00.00" return value if __name__ == "__main__": main() 如果要在Make变量中输

我需要通过makefile运行python脚本。Python脚本执行一些计算并返回一个值。我想在makefile变量中获取该值。我怎么能做到

我想要这样的东西:

mymakefile.mke

$output = python process.py
process.py

import os

def main():
    value = "01.00.00"
    return value
if __name__ == "__main__":
    main()

如果要在Make变量中输入值,可以执行以下操作:

output := $(shell python process.py)
(注意使用
:=
而不是
=
,因为如果使用
=
,Make将在每次计算变量时运行脚本。)


如果希望在配方中的shell变量中使用该值,请查看shell命令行中使用的语法,可能类似于:

output=$(python process.py); echo $output
但在makefile规则中,必须使用更多的美元符号来避开美元符号:

some_target:
    output=$$(python process.py); echo $$output

注意,由于配方的每一行都在它自己的子shell中执行,因此变量的赋值和使用必须在同一行上;当我运行'output:=$(shell python process.py)'时,它将无法保存到下一行。

使用
print()
而不是
return
,它会给我以下错误:'output'未被识别为内部或外部命令,@NaveedAhmad:因为您引入了空格。shell没有将语句视为赋值(赋值操作符在中间),而是看到类似于命令
output
,右边有一些参数,它抱怨不知道如何“输出”。