Python Forum
Simple code works in Jupyter but not VS Code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Simple code works in Jupyter but not VS Code (/thread-22538.html)



Simple code works in Jupyter but not VS Code - Matt_O - Nov-16-2019

Hi Python Experts,

I am extremely new to Python and am trying to work out a small problem.

I am using the latest version of Anaconda Navigator and am launching Jupyter Notebook and VS Code from Anaconda.

In the Python Notebook in Jupyter I can run this code and get the expected result.

import requests
url = 'https://www.bing.com/'
requests.get(url)
<Response [200]>

However, when I run this code using VS Code and the Powershell terminal I just get another prompt (if that is the correct term).
I saved the identical code in the file getURL.py

PS C:\Users\Matthew> python getURL.py
PS C:\Users\Matthew>

I have downloaded and imported the pip install requests for VS Code

I'm wondering if there's something I need to do in VS Code to make sure it's actually sending a request out to the web. Since I launch both Jupyter and VS Code from Anaconda I thought the environments would be set up in a similar way. Apologies if I don't have the terminology correct.

Thanks in advance to anyone who responds. It's much appreciated.

Matt


RE: Simple code works in Jupyter but not VS Code - snippsat - Nov-17-2019

Running as script you need print().
Jupyter Notebook show output automatic as it work the same as a Python REPL(read-eval–print-loop),as you probably seen start with >>>.
import requests

url = 'https://www.bing.com/'
print(requests.get(url))
For some setup tips look at VS Code from start.


RE: Simple code works in Jupyter but not VS Code - Matt_O - Nov-17-2019

Thanks snippsat!

That did the trick.