简体   繁体   English

我如何使用我从等式文件中得到的行

[英]how do I use the line I get from the file in equation

I am processing on json files with python programming.我正在使用 python 编程处理 json 文件。 I want to compare the data from json file with the lines in file.txt and get the output according to the result.我想将 json 文件中的数据与 file.txt 中的行进行比较,并根据结果获取输出。

what should I replace with filex[0] in the code?我应该用代码中的 filex[0] 替换什么?

filename = 'paf.json'
with open(filename, 'r') as f:
        for line in f:
            if line.strip():
               tweet = json.loads(line)

file1=open("file.txt","r")
filex=file1.readlines()
for linex in filex:
    lines=linex

for char in tweet:
    if str(tweet['entities']['urls'][0]['expanded_url']) == filex[0]:
        print(str(tweet['created_at']))
    break

It's hard to tell exactly what you're asking, but I suspect you want to loop through the lines in both files in parallel.很难确切地说出你在问什么,但我怀疑你想并行遍历两个文件中的行。

with open("paf.json", "r") as json_file, open("file.txt", "r") as text_file:
    for json_line, text_line in zip(json_file, text_file):
        tweet = json.loads(json_line)
        if tweet['entities']['urls'][0]['expanded_url'] == text_line:
            print(tweet['created_at'])

This will tell you if line N in the text file matches the URL in line N in the JSON file.这将告诉您文本文件中的第 N 行是否与 JSON 文件中第 N 行中的 URL 匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 function 中使用方程作为参数? - How do I use an equation as an argument in a function? 如何通过搜索文件获得下一行? - How do I get the subsequent line from searching a file? 如何从文本文件中获取每一行并将其拆分,以便我可以在 python 中单独使用它们 - How do I get each line from a text file and split it so that I can use them all separately in python 如何让用户输入可在python中使用的方程式? - How do I get user to input an equation that I can use in python? 我如何让每个线程从我的 txt 文件中逐行使用下一个用户代理 - How do i make each thread use the next useragent line by line from my txt file 如何从 discord 获取用户输入并将其存储为变量以在方程式中使用? Discord.py - How do i take user input from discord and store it as a variable to use in an equation? Discord.py 如何使用Theano求解常微分方程? - How do I use Theano to solve an ordinary differential equation? 如何使用 fsolve 求解二次方程? - How do I use fsolve to solve a quadratic equation? 如何从字典中获取值,通过方程式运行它们并返回具有最大值的键 - How do I get values from a dictionary run them through an equation and return the key with the greatest value 如何获得Python算法的数学方程? - How do I get the Math equation of Python Algorithm?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM