我在做核心课程。练习基于python脚本,我使用的是Visual Studio 2015.在某些时候,我们必须使用库nltk。我正在尝试调试一些我正在调用的代码(我有源代码),并且发生了一些非常奇怪的事情:断点工作,但是我不能使用F10来跳线。它只是跳过所有的脚本。我可以在没有任何问题的情况下调试我的任何脚本,但不能调用库中的脚本。 所以我的问题是:是否有任何选项来“解锁”脚本,以便我可以逐行调试? 我是新来的蟒蛇,我无法找到任何类似的谷歌。我发布代码以防万一有关。 我要调试的功能是“回应”Python脚本锁定在VS 2015中进行调试
from __future__ import print_function
import re
import random
from nltk import compat
reflections = {
"i am" : "you are",
"i was" : "you were",
"i" : "you",
"i'm" : "you are",
"i'd" : "you would",
"i've" : "you have",
"i'll" : "you will",
"my" : "your",
"you are" : "I am",
"you were" : "I was",
"you've" : "I have",
"you'll" : "I will",
"your" : "my",
"yours" : "mine",
"you" : "me",
"me" : "you"
}
class Chat(object):
def __init__(self, pairs, reflections={}):
self._pairs = [(re.compile(x, re.IGNORECASE),y) for (x,y) in pairs]
self._reflections = reflections
self._regex = self._compile_reflections()
def _compile_reflections(self):
sorted_refl = sorted(self._reflections.keys(), key=len,
reverse=True)
return re.compile(r"\b({0})\b".format("|".join(map(re.escape,
sorted_refl))), re.IGNORECASE)
def _substitute(self, str):
return self._regex.sub(lambda mo:
self._reflections[mo.string[mo.start():mo.end()]],
str.lower())
def _wildcards(self, response, match):
pos = response.find('%')
while pos >= 0:
num = int(response[pos+1:pos+2])
response = response[:pos] + \
self._substitute(match.group(num)) + \
response[pos+2:]
pos = response.find('%')
return response
def respond(self, str):
# check each pattern
for (pattern, response) in self._pairs:
match = pattern.match(str)
# did the pattern match?
if match:
resp = random.choice(response) # pick a random response
resp = self._wildcards(resp, match) # process wildcards
# fix munged punctuation at the end
if resp[-2:] == '?.': resp = resp[:-2] + '.'
if resp[-2:] == '??': resp = resp[:-2] + '?'
return resp
# Hold a conversation with a chatbot
def converse(self, quit="quit"):
input = ""
while input != quit:
input = quit
try: input = compat.raw_input(">")
except EOFError:
print(input)
if input:
while input[-1] in "!.": input = input[:-1]
print(self.respond(input))
任何帮助将是非常赞赏。 谢谢。
编辑: 我解决了我的问题,但我还没有找到问题的解决方案。我使用PyCharm(如第一条评论中所建议的),它的功能就像一个魅力。我现在可以调试一切,没有任何问题。根本没有文件修改。我倾向于认为这是Visual Studio Python工具中的一个错误。
你自定义的快捷键?看来F10是“跳过”,你的意思是你想在Debug菜单下使用“Step Into(F11)”?如果添加一个断点,如果调试它,结果如何?其他成员使用PyCharm而不是PTVS作为解决方法:http://stackoverflow.com/questions/37240431/python-tools-visual-studio-step-into-not-working –
嗨,杰克。我没有自定义我的键盘,我保留了所有的默认设置。我不能在该脚本中跳过或跳入,但是我可以在我编写的任何脚本中执行此操作。如果我添加一个断点,它会停止,我可以看到变量的值等,但是如果我按下F10跳到下一行,它只会跳转到该函数中。唯一有效的是,如果我在函数内的每一行中设置一个断点,并且我按F5逐一跳转。它只是没有任何意义。我会尝试PyCharm并发布结果。谢谢 – MBRebaque
不客气。您可以与我分享一个简单的示例,我将使用相同的VS Environment进行调试,因此我们可以知道它是否与VS调试器工具或特定项目类型相关。另一个建议,就像我以前的评论一样,使用PyCharm之类的其他方式代替它作为解决方法。如果你得到任何信息,请随时让我知道:) –