明明有一样的,为神马就是找不到啊?!
从数据库中读取数据,选取符合条件的追加写入文件,部分代码如下~
file_nodeset=open("nodeset.txt","r")
file_relationship=open("follower_followee.txt","a")
t=file_nodeset.readline()
while(''!=t):
cur=conn.cursor()
cur.execute("select * from follower_followee where followee_id=%s",t)
rows=cur.fetchall()
for row in rows:
if (row[0] in nodeSet):
print('haha')
file_relationship.write('%s %s\n' % (row[0],row[1]))
cur.close()
t=file_nodeset.readline()
file_nodeset.close()
file_relationship.close()
row[0]很多都在nodeSet中,可if 之后的语句根本就没有执行。。。row[0]是从数据库中读取的,nodeSet是之前建的集合,都可以打印出来并且手动查找验证的确存在~可能是哪里出问题了啊?求解~~ Python
[解决办法]
rows中有内容吗?注意readline()的返回值带换行符,它是否会影响你的数据库查询命令?
改成"t=file_nodeset.readline().strip()"试试。
[解决办法]
把if那句的括号拆掉试试