我对PHP和Python都是新手。我在PHP的变量$word中有一个单词。我想在Python脚本中使用它,并在我的网页/PHP文件中显示它
我的程序的目的是从PHP中选取一个用户选择的单词,$word,在一组庞大的文本文件中搜索它,每当该单词出现在这些文本文件中,然后打印该文件的文件名和该单词的.concordance结果
我的Python脚本如下
import io, nltk, csv, os
from nltk.text import Text
from nltk import word_tokenize
from pathlib import Path
//Get variable $word from PHP and use it as variable y in Python. Then do the following commands
path="C:\\xampp\\htdocs\\folder1\\folder2\\folder3\\folder4\\"
for root, dirs, files in os.walk(path):
for filename in files:
if filename.endswith(".txt"): # Considering only .txt files
x=os.path.join(root, filename) # Joining .txt file name to its path
text1=io.open(x, encoding="utf-8-sig") # Opening each individual source file
textContent1=text1.read() # Converting it into a string
t=word_tokenize(textContent1)
temp=Text(t)
if y in t:
with open('C:\\xampp\\htdocs\\folder1\\folder2\\p.txt', 'r', newline='', encoding="utf-8-sig") as extended_name:
name_reader=csv.reader(extended_name, delimiter='\t',quoting=csv.QUOTE_NONE)
for row in name_reader:
row_name=row[0]+('.txt')
if filename==(row_name):
row_value=row[1]+row[2]+row[3]+row[4]+row[5]+row[6]+row[7]
print ('\'' + y + '\' word has been found in \'' + row_value + '\'')
temp.concordance(y)
如何从Python文件到PHP文件获取temp.concordance(y)
的结果?这两个文件需要在同一个文件夹中吗
temp.concordance(y)
既不是字符串也不是数组,我想它是一种叫做资源的东西
请帮忙。我是个新手
目前没有回答
相关问题 更多 >
编程相关推荐