question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I run a python script in vscode but the value in the output tab does not match the value in the terminal

See original GitHub issue

Environment data

  • VS Code version: 1.38
  • Extension version (available under the Extensions sidebar): XXX
  • OS and version: windows 8
  • Python3 version (& distribution if applicable, e.g. Anaconda): 3.6.8
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): XXX
  • Relevant/affected Python packages and their versions: XXX
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info #3977): XXX

pic23

Expected behaviour

terminal and output must print 1.5

Actual behaviour

Output tab prints a 0 and terminal value prints a one

pic24 pic25

Steps to reproduce:

Run this code

class Solution:
    def lt(self, p, q, h,start):
           if(q==0 and h ==start):
                   if(0<=p<=1):
                           return p
                   if(p>1):
                           return 1
           if(q<0 or p<0):
                return 0
           a=self.lt((p-1)/2,q-1,h,start) 
           b= self.lt((p-1)/2,q-1,h,start+1)
           return a+b

a=Solution()
print(a.lt(6,2,1,0))

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

XXX

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
mesneymcommented, Sep 11, 2019

I updated the issue template

On Wed, Sep 11, 2019 at 5:33 PM Kim-Adeline Miguel notifications@github.com wrote:

Closing, please fill the issue template and we’ll be happy to reopen this issue.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/microsoft/vscode-python/issues/7337?email_source=notifications&email_token=AHG5UD766356JJJMJBHSTLLQJFP3VA5CNFSM4IVY7WBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6P66SI#issuecomment-530575177, or mute the thread https://github.com/notifications/unsubscribe-auth/AHG5UD3T35KDITAGQ7O2HFTQJFP3VANCNFSM4IVY7WBA .

0reactions
kimadelinecommented, Sep 11, 2019

First, please note that the Code Runner extension isn’t related to the Python extension for VS Code.

It looks like you have multiple versions of Python installed, so if you run python in a terminal window without an active virtual environment it will start the interpreter for Python 2.7, and to get Python 3.X you would have to run python3.

Manually running python <yourfile.py> returns 0, while running python3 <yourfile.py returns 1.5.

If you modify the code-runner.executorMap setting for the Code Runner extension you will see that it calls python -u for Python files and not python3 -u.

If you look at the Configuration section for the Code Runner extension, they mention this custom parameter:

$pythonPath: The path of Python interpreter (set by Python: Select Interpreter command)

which you could use in code-runner.executorMap.

Related upstream issue: https://github.com/formulahendry/vscode-code-runner/issues/524.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio Code is not showing the ouput of Python
Save this file, then go to the Terminal tab at the bottom and type python hello.py and press Enter. This should run the...
Read more >
Debugging configurations for Python apps in Visual Studio Code
Switch to the Run and Debug view (Ctrl+Shift+D), select the appropriate configuration from the debugger dropdown list, and start the debugger. The debugger ......
Read more >
Editing Python in Visual Studio Code
is a simple way to take whatever code is selected, or the code on the current line if there is no selection, and...
Read more >
Get Started Tutorial for Python in Visual Studio Code
Linux/macOS: open a Terminal Window and type the following command: python3 --version · Windows: open a command prompt and run the following command:...
Read more >
Tasks in Visual Studio Code
Possible values are: shared - The terminal is shared and the output of other task runs are added to the same terminal. dedicated...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found