Afke
Afke

Reputation: 989

Visual Studio forgets earlier defined functions Python

I am very new to Visual Studio and I ran into a problem. I am trying to run the following code in Python in Visual Studio:

#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()

If I run the entire piece of code I get no errors. But if I run line by line I get errors like:

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

Since the entire script is a lot longer I don't want to run the entire script each time I added a new line. How to get over this? And is there an easy way (shortcut) to run 1 line and move automatically to the next with my cursor? Thank you.

Upvotes: 0

Views: 48

Answers (1)

JustLudo
JustLudo

Reputation: 1790

Although the question is somewhat vague (there is no "running line by line" in Python) I think you may want to debug the code. This way you should be able to step through your code and skip pieces or hook into certain parts.

How to setup python debugging in Visual Studio is described here

Upvotes: 1

Related Questions