结构化文本查询

博客探讨了在处理tab-delimited文件时,如何检查第三列是否包含特定单词并根据第四列内容输出相应结果的问题。指出原始Python代码的不足,并推荐使用SPL语言进行更简洁的结构化查询,包括动态条件查询和在不同应用程序中调用SPL脚本的方法。
摘要由CSDN通过智能技术生成

【问题】

I'm trying to check whether column 3 of a tab-delimited file contains a certain word. If it does not, it should continue reading. If it does contain the word, it should check column 4. Depending on whether there is content in column 4, the output should be something found or something not found.

I'm not stuck on the second part of this, i.e. checking column 4. My output gives me"something found" when there is in fact no content there.

for line in f:

    if line.strip()split("\t")[2] == "word":

        print ("word")

        if line.strip().split("\t")[3] is not None:

            print ("something found")

        else:

            print("nothing found")

The file looks like this:

reference #1 reference #2 notword content ...(more columns)
reference #1 reference #2 word content ...
reference #1 r

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值