在功能中调试:无法列出压缩对象?

时间:2018-10-31 22:50:53

标签: python debugging zip pdb

我正在尝试像这样调试函数-- Returns person 2 and 4. SELECT PersonId FROM activity WHERE PersonId NOT IN ( -- People to exclude. SELECT PersonId FROM activity WHERE Club = 'Orchestra' ) GROUP BY PersonId ;

one_away

我可以这样写:

import pdb


def is_one_away(first: str, other: str) -> bool:

    skip_diff = {
        -1: lambda i: (i, i + 1),
        1: lambda i: (i + 1, i),
        0: lambda i: (i + 1, i + 1)
    }
    try:
        skip = skip_diff[len(first) - len(other)]
    except KeyError:
        return False
    pdb.set_trace()
    for i, (l1, l2) in enumerate(zip(first, other)):
        if l1 != l2:
            i -= 1
            break

运行到import one_away one_away.is_one_away('pale', 'kale') 时,我想查看pdb.set_trace()的结果。所以我写:

zip(first ,other)

但是如果在Python控制台中,它可以工作:

(Pdb) >? list(zip(first, other))
*** Error in argument: '(zip(first, other))'

为什么?

1 个答案:

答案 0 :(得分:2)

CREATE PROCEDURE [dbo].[sp_CreateTable] @subjectOfTable VARCHAR(30) AS BEGIN IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID (@tabName) AND type in (N'U')) DROP TABLE [dbo].[@tabName] CREATE TABLE @tabName ( [ID] [INT] IDENTITY(1,1) NOT NULL, [RankID] [INT] NOT NULL, [SlotTime] [NVARCHAR](10) NOT NULL, [SlotDate] [NVARCHAR](30) NOT NULL ) ON [PRIMARY] END 是调试外壳程序中的内置命令:

import pyspark.sql.functions as F
from datetime import datetime

data = [
  (1, datetime(2017, 3, 12, 3, 19, 58), 'Raising',2),
  (2, datetime(2017, 3, 12, 3, 21, 30), 'sleeping',1),
  (3, datetime(2017, 3, 12, 3, 29, 40), 'walking',3),
  (4, datetime(2017, 3, 12, 3, 31, 23), 'talking',5),
  (5, datetime(2017, 3, 12, 4, 19, 47), 'eating',6),
  (6, datetime(2017, 3, 12, 4, 33, 51), 'working',7),
]
df.show()

| id|       testing_time|test_name|shift|
|  1|2017-03-12 03:19:58|  Raising|    2|
|  2|2017-03-12 03:21:30| sleeping|    1|
|  3|2017-03-12 03:29:40|  walking|    3|
|  4|2017-03-12 03:31:23|  talking|    5|
|  5|2017-03-12 04:19:47|   eating|    6|
|  6|2017-03-12 04:33:51|  working|    7|

所以当您键入

list

它试图将其解释为传递给pdb的命令。相反,您想在python中执行(或(Pdb) help list l(ist) [first [,last] | .] List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing. With . as argument, list 11 lines around the current line. With one argument, list 11 lines starting at that line. With two arguments, list the given range; if the second argument is less than the first, it is a count. The current line in the current frame is indicated by "->". If an exception is being debugged, the line where the exception was originally raised or propagated is indicated by ">>", if it differs from the current line. rint)表达式:

(Pdb) list(zip(first, other))