首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在EOT中插入带有PHP变量的python代码

在EOT中插入带有PHP变量的python代码
EN

Stack Overflow用户
提问于 2017-06-04 18:50:45
回答 0查看 350关注 0票数 3

我正在尝试用PHP生成一个Python脚本。PHP脚本在python代码中嵌入变量,然后输出生成的python脚本。

使用<<<EOT时,它应该读取php变量,而不使用任何其他变量(比如python相关的)。

代码语言:javascript
复制
 // 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 =  <<<EOT
    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;
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44353246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档