php eot 变量,在EOT内插入带有PHP变量的python代码

我正在尝试使用PHP生成Python脚本. PHP脚本将变量嵌入python代码中,然后输出结果python脚本.

使用<<< EOT,它应该读取php变量,同时保留其他变量(例如与python相关的变量)

// PHP Var

$date = '12/04/2017';

$id = '2';

$phparray['value1'] = '03:45';

$phparray['value2'] = '08:00';

$phparray['value3'] = '17:00';

$phparray['value4'] = '21:30';

// Embed Variables in the Python script code to be later generated

$PythonContents = <<

I'm, trying to embed "$phpvar" inside python code.

'''

Python script generated on {$date}

'''

# Python Function specific imports

import datetime

################ Python configs ############

myvar = 'fixed'

function_id = {$id}

Python-With-PHP-var-Range = [['{$phparray['value1']}','{$phparray['value2']}'],['{$phparray['value3']}','{$phparray['value4']}']]

Result-IN-Python-range = [['03:45','08:00'],['17:00','21:30']]

Python-and-PHP-var2 = {

'{$generateID}/f/{$data_sensor['device_id']}/test/{$data['heatControlRelay']}/rstate': 'heatingisLocked',

}

ResultINPython = {

'44/f/folder1/test/85111': 'Value',

}

################ End of Python config #############################

################ Python script below #############################

################ End of Python script #############################

EOT;

echo $PythonContents;

解决方法:

主要的破损是在结束EOT之前有额外的间距,但也充满了未定义的变量.

所以这是固定的:

// PHP Var

$generateID = '123';

$data_sensor['device_id'] = 'xyz';

$data['heatControlRelay'] = '12345';

$date = '12/04/2017';

$id = '2';

$phparray['value1'] = '03:45';

$phparray['value2'] = '08:00';

$phparray['value3'] = '17:00';

$phparray['value4'] = '21:30';

// Embed Variables in the Python script code to be later generated

$PythonContents = <<

I'm, trying to embed "\$phpvar" inside python code.

'''

Python script generated on {$date}

'''

# Python Function specific imports

import datetime

################ Python configs ############

myvar = 'fixed'

function_id = {$id}

Python-With-PHP-var-Range = [['{$phparray['value1']}','{$phparray['value2']}'],['{$phparray['value3']}','{$phparray['value4']}']]

Result-IN-Python-range = [['03:45','08:00'],['17:00','21:30']]

Python-and-PHP-var2 = {

'{$generateID}/f/{$data_sensor['device_id']}/test/{$data['heatControlRelay']}/rstate': 'heatingisLocked',

}

ResultINPython = {

'44/f/folder1/test/85111': 'Value',

}

EOT;

echo $PythonContents;

标签:python,php

来源: https://codeday.me/bug/20191111/2018925.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值