php执行python 脚本乱码

#!/usr/bin/python3
import sys
import imp
import jieba
import jieba.posseg as psg
import urllib.parse ################################################################################### 转义代码
import io  ###################################################################################转义代码
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') ########################### 转义代码

data = urllib.parse.unquote(sys.argv[1]) ########################### 转义代码
def getPort(word): jieba.load_userdict("字典库") seg_list = psg.lcut(word) portList="" for x in seg_list: if x.flag.startswith('qipei'): portList += x.word+',' print(portList) getPort(data)

  

<?php
header("Content-type: text/html; charset=utf-8");
$data = urlencode($_GET['q']);
exec('python3 绝对路径python脚本 '.$data,$b);
var_dump($b);

  

原文地址:https://www.cnblogs.com/chengfengchi/p/12954834.html