Sunday 15 January 2012

mysql python hangup debugging -


My program is not ending ... As I'm relatively new to Python, I suspect I have not made a general mistake. I have not seen so far recently in Java I have solved such simple problems by closing a file ...

Note: < / Strong> rt_table has 250,000 rows before this Python program I wrote a par Java program and I It was not taken much time to execute.

  def create_amatrix (): "" "" from Ritvet create adjacency table of network proximity matrix Arti_tebl "" con = mdb.connect (host = "localhost" user = "root" , Password = "", db = "twitter") CUR = con.cursor (mdb.cursors.DictCursor) #get Group of users in the peak retweeter network cur.execute ("user_id select from users") rows = rows in rows. Fetchall () vSet = list for UID: vSet.append (UID) #populate proximity table cur.execute ("select * rt_table") line Issues = cur.fetchall () to line up in rows: sourceUserID = row [try "source_user_id"] sourceUserName = row [ "source_user_name"] rtUserID = row [ "rt_user_id"] rtUserName = row [ "rt_user_name"]: curRow = vSet.index (sourceUserID) curCol = vSet.index (rtUserID) except ValueError: cur.execute (continue select "proximity COUNT (*) where r =% s and c =% s", (curRow, curCol )) if cur.fetchone () [ 'COUNT (*)'] == 0: Try: cur.execute ( "enter proximity (R, C, Val, source_user_id, source_user_name, rt_user_id, rt_user_name) value (% d, % D,% d,% d% s,% d,% s "), except (curRow, curCol, 1, sourceUserID, SourceUserName, rtUserID, rtUserName): con.rollback () Please try: cur.execute ("update adjacency set val = val + 1 where r =% d and c =% d"), except curit (currow, curCol): con.rollback () cur Close () con.close ()   
  1. Where's my error?
  2. What can I do to know what my code is doing? Specifically, can I ask what code is executing the program?

    All help is greatly appreciated, and to make your code more dragon, make suggestions free!

    One potential problem I can see is this snippet:

      try: curRow = vSet.index (SourceUserID) curCol = valueError except vSet.index (rtUserID):   

    list.index () function O (n) Finds the list in time. You are also calling it O (N) times, so your overall efficiency is O (N ^ 2) with N = 250,000, this is a very inefficiency I have not shown any clear errors in your code, so I think That is the reason that he is not returning back, because it will take some time to complete, and you are not waiting for that long time.

    One thing you can try is to replace vSet with a dict; By looking at your code, it seems that the vet that you use is looking at the different user id indicator , So try changing it:

      list for the UID in line: VSet.append (uID)   

    with this: VSet = dict for the

      index, line in enumerate (rows): vSet [row ['user_id']] = index   

    things in a DC Do o (1) opera Not, so it should take O (n) Total runtime. Also, note that instead of putting uid in the lookup dot (which is in a row), I use the actual user_id value Put - because later, you are watching the User ID, not the rows. I have not run my code to test it, but I suspect that it was gone to complete, then you would think that you had zero output lines because the ints DB does not compare to the equivalent of the cursor rows and therefore To set your code, curu and curCol are never successful.

    Oh, and of course, try your curRow and curCol :

     : curRow = except vSet [sourceUserID] curCol = vSet [rtUserID] IndexError: attempt to create   

    in order to continue to see those changes, and see what works best for your code is.

    In addition, the advice to sprinkle the print statement given in your code is a good one, I usually try before reaching for the debugger, and for more time I Indicates what the code is doing, and I do not have to remove the bigger guns in Debugger if you want a Python debugger, however, read on how to use Google for pdb and how to use it < / P> You can use it from the command line Not, or it you're way, you can integrate it.

No comments:

Post a Comment