我是Visual Studio的新手,遇到了一个问题。我尝试在Visual Studio中用Python运行以下代码:
#importing packages
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
#my_url = "https://m.mcdonalds.be/nl/restaurant"
my_url = "https://www.newegg.com/global/be-en/p/pl?d=graphics+cards"
#opening connection, grabbing the page
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
如果我运行整段代码,我不会得到任何错误。但是如果我逐行运行,我会得到如下错误:
Traceback (most recent call last):
File "d:\HLIS-Administration\..\tempCodeRunnerFile.py", line 1, in <module>
page_html = uClient.read()
NameError: name 'uClient' is not defined
由于整个脚本要长得多,所以我不想在每次添加新行时都运行整个脚本。如何克服这一点?有没有一种简单的方法(快捷方式)来运行一行,并用光标自动移动到下一行?谢谢你。
发布于 2020-01-02 13:23:13
尽管这个问题有点模糊(Python中没有“逐行运行”),但我认为您可能想要调试代码。这样,您应该能够单步执行您的代码,并跳过某些部分或挂钩到某些部分。
here描述了如何在Visual Studio中设置python调试
https://stackoverflow.com/questions/59563996
复制