我的程序似乎并没有终止...因为我相对较新的python我会怀疑我犯了一个常见的错误,我还没有看到。即使最近在Java中,我通过关闭文件解决了这样的简单问题...mysql python挂断调试
注意:rt_table
有大约250,000行。在这个python程序之前,我编写了一个等效的Java程序,并且不需要很长时间就可以执行。
def create_AMatrix():
"""Create the adjacency table of the retweet network from rt_table to create an adjacency matrix"""
con = mdb.connect(host="localhost", user="root", passwd="", db="twitter")
cur = con.cursor(mdb.cursors.DictCursor)
#get vertex set of users in retweet network
cur.execute("select user_id from users")
rows = cur.fetchall()
vSet = list()
for uID in rows:
vSet.append(uID)
#populate adjacency table
cur.execute("select * from rt_table")
rows = cur.fetchall()
for row in rows:
sourceUserID = row["source_user_id"]
sourceUserName = row["source_user_name"]
rtUserID = row["rt_user_id"]
rtUserName = row["rt_user_name"]
try:
curRow = vSet.index(sourceUserID)
curCol = vSet.index(rtUserID)
except ValueError:
continue
cur.execute("select COUNT(*) from adjacency where r = %s and c = %s", (curRow, curCol))
if cur.fetchone()['COUNT(*)'] == 0:
try:
cur.execute("insert into adjacency (r, c, val, source_user_id, source_user_name, rt_user_id, rt_user_name) values (%d, %d, %d, %d, %s, %d, %s"), (curRow, curCol, 1, sourceUserID, sourceUserName, rtUserID, rtUserName)
con.commit()
except:
con.rollback()
else:
try:
cur.execute("update adjacency set val = val+1 where r = %d and c = %d"), (curRow, curCol)
con.commit()
except:
con.rollback()
cur.close()
con.close()
- 哪里是我的错误?
- 我能做些什么来找出我的代码在做什么?具体来说,我可以问问程序正在执行哪一行代码?
所有帮助非常感谢,并随时提出建议,使我的代码更Pythonic!我可以看到
我收到你了吗?你正在寻找一个调试器? http://docs.python.org/2/library/pdb.html – bash0r
我也在寻找我的错误在哪里......即使使用调试器,我仍然可能找不到它 – CodeKingPlusPlus
我不喜欢python,因为它取决于在空白处。修复一个有选项卡的bug并且在下一行有4个空格是一种痛苦。对不起,我无法帮助你。 – bash0r