Reputation: 359
I'm doing the nucleai courses. Exercises are based on python scripts and I'm using Visual Studio 2015. At some point, we have to use the library nltk. I was trying to debug some code I'm calling (I have the source) and something really weird happens: breakpoints work, but I can't use F10 to jump line to line. It just skips all the script. I can debug without any problem any of my scripts but not those within the library. So my question is: is there any option to "unlock" the script so I can debug line by line? I'm new with python and I can't find anything similar on google. I'm posting the code in case something is relevant. The function I want to debug is 'Respond'
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))
Any help will be very much appreciated. Thanks.
EDIT: I solved my problem but I haven't found a solution for the question. I'm using PyCharm (as suggested in the first comment) and it works like a charm. I can debug everything without any problem now. No file modification at all. I'm inclined to think that this is a bug in Python tools for Visual Studio.
Upvotes: 0
Views: 159
Reputation: 6436
Other members also got the similar issue, my suggestion is that you can use the PyCharm instead of PTVS as a workaround. Of course, you could also start a discussion(Q AND A) from this site for PTVS tool:
https://visualstudiogallery.msdn.microsoft.com/9ea113de-a009-46cd-99f5-65ef0595f937
Upvotes: 1