数据库中确实存在,可并没有写入文件……不知道问题出在哪里
部分代码如下: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()数据库Python
部分代码如下: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()数据库Python
如果查询都没有结果,肯定没有数据写入文件.
你可将
print('haha')
改为
file_relationship.write('%s \n' % ('haha'))
如果有循环,肯定有会写"haha"到文件里
rows=cur.fetchall() 这个语句能够获取出数据
row[0]和nodeSet分别都可以打印出来,手动查找row[0]有很多都在nodeSet中,可他就是没有执行if之后的语句!!
1.跑程序的时候会跳出这样的警告
Warning (from warnings module):
File "D:\WHY\0.2.py", line 58
cur.execute("select * from follower_followee where followee_id=%s",t)
Warning: Incorrect integer value: '
' for column 'followee_id' at row 1
可是在这一行上面也有完全一样的语句却没警告……
2.再用以下语句将集合中的元素写入文件时,为什么文件中会出现空行for node in nodeSet:
file_nodeset.write('%s\n'%node)求大神解答啊~~问题可能出在哪里?
另外在python中要如何设置断点调试呢