---
# System prepended metadata

title: LeetCode 有時候吐出的submit failed message 一大坨，這樣是要怎麼debug啦 = =
tags: [GitHub - DSA2019]

---

###### tags: `GitHub - DSA2019`
# LeetCode 有時候吐出的submit failed message 一大坨，這樣是要怎麼debug啦 = =

在LeetCode上submit你辛苦打完的答案之後，

發現他給你一大坨難讀的訊息時，

此刻的你對於自己的演算法有強大的自信，並且不想輕易改寫運算邏輯，

但是又看了好久還是卡在那邊時，你可以這樣做。

![](https://i.imgur.com/NoRxDNq.png)
<br><br><br>


1.點擊 View All
![](https://i.imgur.com/qpZZqux.png)
<br><br>

2.整理參數，紅框內的是function名稱，未框起來的是input到function的參數
![](https://i.imgur.com/AN5I9Fo.png)
<br><br>

3.打開python編輯軟體，建構function list
![](https://i.imgur.com/RPSXYEU.png)
<br><br>

4.建構input list
![](https://i.imgur.com/6rGSMVB.png)
<br><br>

5.複製LeetCode網頁的output，並建構 output list (記得用replace 把 null 換成 'null'喔)
![](https://i.imgur.com/LcsuAuC.png)
<br>
![](https://i.imgur.com/HLGiIhu.png)
<br><br>

6.複製LeetCode網頁的Expected，並建構 Expected list (記得用replace 把 null 換成 'null'喔)
![](https://i.imgur.com/EtrPh2l.png)
<br>
![](https://i.imgur.com/tAjP4W4.png)
<br><br>


7.比較Output和Expected，並建立boolean欄位已找出錯誤點，利用pandas輸出成Excel檔案，方便觀看
![](https://i.imgur.com/dhJqfpa.png)
<br><br>

[附上程式碼](https://github.com/JetVayne/DSA2019/blob/master/NoteCode%20-%20py.eval%20for%20debug%20on%20LeetCode/make_excel.py) 

7.打開Excel檔案，找到錯誤點 (第(53-1)次的get有錯)
![](https://i.imgur.com/ypocRXN.png)
<br><br>

8.透過eval()模擬LeetCode測試情形 (利用迴圈模擬)
```python=
funList = ["MyLinkedList", "addAtHead", "get", "addAtHead", "addAtTail", "get", "addAtIndex", "addAtHead", "addAtHead",
           "addAtHead", "addAtHead", "addAtHead", "addAtIndex", "addAtIndex", "get", "get", "addAtIndex", "get",
           "addAtHead", "addAtIndex", "addAtIndex", "addAtHead", "addAtIndex", "addAtIndex", "addAtHead", "get",
           "deleteAtIndex", "addAtIndex", "get", "get", "deleteAtIndex", "addAtTail", "addAtHead", "addAtTail",
           "addAtHead", "addAtTail", "addAtTail", "addAtIndex", "get", "get", "addAtHead", "deleteAtIndex",
           "deleteAtIndex", "get", "deleteAtIndex", "get", "addAtIndex", "addAtTail", "addAtHead", "addAtTail",
           "addAtHead", "get", "addAtTail", "addAtTail", "addAtHead", "get", "get", "addAtHead", "addAtHead",
           "addAtIndex", "addAtHead", "addAtHead", "addAtHead", "addAtHead", "addAtHead", "addAtTail", "addAtIndex",
           "addAtHead", "addAtTail", "deleteAtIndex", "addAtHead", "addAtHead", "addAtIndex", "addAtTail", "addAtIndex",
           "addAtTail", "addAtIndex", "get", "addAtIndex", "addAtIndex", "get", "addAtTail", "addAtTail", "addAtHead",
           "addAtHead", "addAtHead", "deleteAtIndex", "addAtHead", "addAtTail", "addAtTail", "addAtTail", "addAtTail",
           "addAtHead", "addAtHead", "addAtTail", "addAtTail", "addAtIndex", "get", "addAtTail", "addAtHead",
           "addAtTail", "addAtHead"]

inputList = [[], [56], [1], [41], [98], [3], [1, 33], [72], [52], [89], [0], [98], [7, 97], [2, 51], [1], [6], [6, 49],
             [8], [72], [7, 8], [8, 58], [10], [3, 6], [9, 61], [63], [16], [7], [16, 55], [4], [10], [6], [96], [69],
             [20], [3], [44], [4], [8, 16], [15], [21], [41], [1], [11], [21], [22], [2], [5, 7], [62], [95], [91],
             [69], [24], [51], [94], [93], [29], [10], [68], [13], [32, 42], [48], [55], [79], [5], [36], [32],
             [25, 40], [8], [68], [30], [66], [92], [27, 26], [90], [11, 19], [68], [17, 62], [15], [17, 97], [35, 89],
             [44], [90], [67], [2], [51], [30], [38], [30], [43], [76], [16], [38], [82], [81], [67], [67], [3, 16],
             [57], [94], [11], [31], [50]]

# funList = ["MyLinkedList", "addAtHead", "get", "addAtHead", "addAtTail", "get"]
# inputList = [[], [56], [1], [41], [98], [3]]

tester = MyLinkedList
test_time = 0
for fun, input in zip(funList, inputList):
    test_time += 1
    tempDemand = str(fun) + str(input)
    tempDemand = tempDemand.replace('[', '(').replace(']', ')')
    print(tempDemand)
    if tempDemand == 'MyLinkedList()':
        tester = eval(tempDemand)
    else:
        eval('tester.'+tempDemand)

    print('look:',tester.display())
    print()
```
<br><br>
9.找到要觀測的code part
![](https://i.imgur.com/3ZfqW9w.png)
<br><br>

10.利用debug模式查找並測試
![](https://i.imgur.com/w6XtRFx.png)
<br><br>

## ♘ Coding Tips I Found
- 使用 PyCharm debug 的時候，若專案中，有 folder 或是 package 的檔案名稱和 python 預設的 moudule 的名稱相同的話，會無法使用 PyCharm 的 debug mode
    - ex:  MyProject(folder)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ∟ Queue(mypackage) -> debug mode broken
