Python Forum
Visual Studio Code does not print desired output but only prints "..." - 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: Visual Studio Code does not print desired output but only prints "..." (/thread-20980.html)

Pages: 1 2


Visual Studio Code does not print desired output but only prints "..." - vincentolivers - Sep-09-2019

Hi all,

I'm a Python rookie (doing an online Python for Beginners course via edX) and I'm struggling with the following.
When I want to execute the below-stated lines of code:

fhand = open("mbox-short.txt")
for line in fhand:
    line = line.rstrip()
    if line.startswith("From: "):
        print(line)
, it prints the following:
Vincents-MacBook-Air-4:PYTHON DATA  STRUCTURES vincentolivers$ /usr/bin/python
Python 2.7.10 (default, Aug 17 2018, 19:45:58) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> fhand = open("mbox-short.txt")
>>> 
>>> for line in fhand:
...     line = line.rstrip()
...     if line.startswith("From: "):
...         print(line)
... 
Any ideas on how to print my desired output instead of "...", i.e. all lines that start with "From: " in the handled text file?

Thanks in advance!!


RE: Visual Studio Code does not print desired output but only prints "..." - perfringo - Sep-09-2019

First - it's recommended to open files with 'with' statement a la with open('mbox-short.txt', 'r') as f:

Second - if you try to enter code in interactive interpreter then you should make sure indentation is correct a la:

>>> for i in range(3):
...     print(i)
...
0
1
2
>>>
Third - it is not recommended to use Python 2 (for example print is quite different between Python 2 and 3)


RE: Visual Studio Code does not print desired output but only prints "..." - buran - Sep-09-2019

it looks like you perform "Run Selection/Line in Python Terminal" command (from the mouse right-click menu). In this case it execute your script/selection/current line in python interactive mode line by line
You need to use "Run Python File in Terminal" instead


RE: Visual Studio Code does not print desired output but only prints "..." - vincentolivers - Sep-09-2019

@burak thanks for your reply! And I'm sorry for not using that template, I just signed up and quickly wanted to get my problem solved which led to overreading those rules. I will take them into account from now onwards.

Content-wise, I actually do not see any "Run Python File in Terminal" option... Also, I downloaded the latest version of Python multiple times but somehow it keeps on using the 2.7.10 version...


RE: Visual Studio Code does not print desired output but only prints "..." - buran - Sep-09-2019

How do you run your code?
it's in the right-click mouse menu, when click in the code part of the IDE window

as to 2/3 problem - you can select which interpreter to use in VSCode
Ctrl+Shift+P -> find Select Interpreter command
you are on linux paython defaults to python2 version


RE: Visual Studio Code does not print desired output but only prints "..." - vincentolivers - Sep-09-2019

I indeed run the code by selecting the lines --> right-click --> "Run Python File in Terminal".
The other option when right-clicking is "Run Current File in Python Interactive Window". However, when I click that option, VSC requires me to install Jyputer. Apparently Jyputer is installed but it can't be run since my Python version is not supported, can that be true?


RE: Visual Studio Code does not print desired output but only prints "..." - buran - Sep-09-2019

[attachment=698]

this is the right-click menu I have. I believe you use the Run selection/line in python terminal


RE: Visual Studio Code does not print desired output but only prints "..." - vincentolivers - Sep-09-2019

Mine lacks the 2nd "run" option compared to yours...


RE: Visual Studio Code does not print desired output but only prints "..." - buran - Sep-09-2019

what version of VSCode/Python extension do you use?


RE: Visual Studio Code does not print desired output but only prints "..." - vincentolivers - Sep-09-2019

Python 2.7.10 64-bit.

Maybe I should consider reinstalling Python since there could be a chance I've unconsciously changed some vital settings or so. Also, how is it possible that even though I downloaded Python 3.7, only the 2.7.10 version pops up as possible interpreter? I'm kinda lost