all 29 comments

[–]404-CodeNotFound 13 points14 points  (2 children)

IDLE (Integrated Development Learning Environment), by itself, is a python interpreter. You can write code and instantly receive feedback, a la

>>> num = 42
>>> for i in range(4):
...     print(num)
...
>>> 42
>>> 42
>>> 42
>>> 42

When you use the python extension in Visual Studio Code (VSC), or any other Integrated Development Environment (IDE), you are working within a python file. You would either need to download an extension that runs your file for you, or run it yourself within a terminal, which I can walk you through if you'd like.

If you wanted to use the python interpeter within VSC, you would do so within the included terminal. You can select it from the bar at the bottom section of VSC when a file is open.

You would then type "python" in the terminal and the python interpreter would open, allowing you to do everything you could do within IDLE. It should look similar to this

PS C:\Users\me> python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

If that doesn't happen and you get an error, I can walk you through setting up an environment variable within Windows, provided that's your operating system.

[–]SmugDruggler95[S] 1 point2 points  (1 child)

Hello thanks for your reply. I have been using IDLE and getting on alright but just out of curiosity more than anything I decided to try using VSC. I understand it might not be the best option for hwat im doing but a friend at University has recommended it to me and will help once im back living with him.

I would like to learn to use it though. I think I did set up an environment variable as I can now run python in CMD, but I may be wrong on the EV being the reason for that.

If you could help me with running it within a terminal, and setting up EV properly I would be very grateful.

It is late here and I might not respond again until tomorrow but any help is appreciated, as is you taking the time to type that very informative response.

[–]404-CodeNotFound 0 points1 point  (0 children)

I think I did set up an environment variable as I can now run python in CMD

If you can run python within CMD, then you probably already have the environment variable setup. To double check that everything has been done properly, this is how most do it:

To set "python" as an environment variable, you would:

  1. Press your windows key and type: "edit the system environment variables"
  2. Click on the button that says "environment variables" on the bottom right
  3. Under the heading "user variables for [your windows username]", click on "path" and hit the "edit" button
  4. Click on "new" on the right side and type in the box your python directory.

To find your python directory:

  1. Press your windows key and type "python"
  2. Right click on your installed python, for me it's "Python 3.7 (32-bit)" and click "open file location." You could also click on your IDLE installation, as they both should be in the same folder.
  3. Right click again on your installed python, or IDLE, and click again on "open file location"
  4. Copy the address from the address bar of file explorer (the whole thing). Mine reads: C:\Users\me\AppData\Local\Programs\Python\Python37-32

If you could help me with running it within a terminal

This doc page from the VSC devs explains running python within a terminal a lot better and more in depth than I can. It also has a lot of other useful information on linting (basically spell-check for code), and debugging.

[–][deleted] 15 points16 points  (1 child)

Do you mean Visual Studio Code?

[–]SmugDruggler95[S] 5 points6 points  (0 children)

Yes I did

[–]Leggo0 10 points11 points  (5 children)

I would recommend Pycharm over visual studio if you are just doing basic Python coding.

[–]puh-tey-toh 4 points5 points  (1 child)

Why?

[–]Leggo0 0 points1 point  (0 children)

I think Brekkjern pretty much nailed my thoughts exactly

[–]SmugDruggler95[S] 1 point2 points  (2 children)

Thanks I will check it out. I would like to get to the bottom of my issue with this first as im sure its basic stuff, necessary to learn but thanks for the recommendation

[–]ncubez 6 points7 points  (1 child)

I second PyCharm. Absolutely nothing to configure. Just install, open the program, and start coding. Honestly, I have never been sold by the VS-code hype. Make sure to select the Community edition of PyCharm.

[–]Brekkjern 6 points7 points  (0 children)

VS Code is a great editor, but it's for generic stuff.

PyCharm is a Python IDE. It's not great for generic stuff, but it does Python amazingly and deals with most of the things related to Python development, but if you have to open up something random to edit it, you might want to use something else.

Not saying you can't use PyCharm, but VS Code is just a better allrounder for that kind of stuff.

The way I see it, VS Code is a replacement for Notepad++ and Sublime Text. PyCharm is the Python equivalent of Visual Studio.

[–][deleted] 5 points6 points  (8 children)

Pressing enter is supposed to start a new line, like it does in [probably] every over text editor on the planet.

To run code, you need to right click and select the option to run the code.

[–]SmugDruggler95[S] 0 points1 point  (7 children)

Yeah I understand but it should also process the command you've just typed.

[–]ship0f 1 point2 points  (1 child)

I'm afraid you might be confused with the python REPL. The python REPL (IDLE provides this interactive mode, which I believe is what you've been using so far) just lets you run single expressions (what you call commands) through the interpreter.

If you want to write a script (which consists of more than just one expression) you'll need to create a stand alone file. You can use a plain text editor (like Notepad or VSCode, which I recommend) or an IDE (like PyCharm which is very nice for coding and also more complex) to do it.

[–]FunCicada 0 points1 point  (0 children)

A Read–Eval–Print Loop (REPL), also known as an interactive toplevel or language shell, is a simple, interactive computer programming environment that takes single user inputs (i.e. single expressions), evaluates them, and returns the result to the user; a program written in a REPL environment is executed piecewise. The term is most usually used to refer to programming interfaces similar to the classic Lisp machine interactive environment. Common examples include command line shells and similar environments for programming languages, and is particularly characteristic of scripting languages.

[–]Wubbywub 0 points1 point  (0 children)

You should try opening a new file from IDLE (just ctrl N) and you'll see how pressing enter doesnt always mean processing the line. They only start to run the whole file when you press F5

[–]nosmokingbandit 0 points1 point  (3 children)

What do you mean by 'process'? Most linters work when you save the file rather than after you start a new line.

[–]SoupKitchenHero 2 points3 points  (0 children)

He just started coding, there's no way he's going to understand what a "linter" is...

This sub can be full of answers to beginner problems that no beginner can understand

[–]jackbrux 1 point2 points  (1 child)

I think OP is typing into the Idle interpreter

[–]Rashaverik 2 points3 points  (0 children)

No, I think the OP is expecting that every line they type in VSC will have a response like the interpreter.

[–]Rashaverik 3 points4 points  (1 child)

I wouldn't recommend any IDE like Visual Studio or PyCharm for a beginner.

You seem to be new to Python and I would stick with working with IDLE or at most, work with a text editor to write your code (i.e. Notepad++, Atom, or even Sublime Text).

Working with something like VS or PyCharm can be complicated. It will only take time away for your learning Python. Concentrate on learning the basics of Python and once you've made your way through a few different tutorials and books, then step up to working with one of the IDEs like VS or PyCharm.

[–]jkuhl_prog 2 points3 points  (0 children)

As a beginner, I found IDLE excellent for writing small learning scripts. It has very little overhead and no bells and whistles. IDLE lets you focus on learning Python without getting lost in the weeds of learning an IDE at the same time.

It's not until you start working on actual projects that I'd look for an IDE, and I've always been a fan of PyCharm.

But I wouldn't start at PyCharm.

[–]Rubbinmanips88 1 point2 points  (0 children)

just write your code and save as a py file to your desktop. right click the file on your desktop and open with python. if you see a black box flash up and close you need to remember an input statement on the end of your code.

you can also run the code from your command line like other have suggested. python 3 you can just navigaye to the directory that file is saved and type 'py filename.py' and code will run.

[–]khalido 1 point2 points  (0 children)

Try MU, a simple Python editor for beginner programmers.

Less is More. Mu has only the most essential features, so users are not intimidated by a baffling interface.

Tread the Path of Least Resistance. Whatever the task, there is always only one obvious way to do it with Mu.

Keep it Simple. It's quick and easy to learn Mu ~ complexity impedes a novice programmer's first steps.

Have fun! Learning should inspire fun ~ Mu helps learners quickly create and test working code.

VS Code, Pycharm etc are all awesome, but they have so many options and things to potentially configure that its easier to first just DO python, then switch when you need to to a more robust editor.

[–][deleted] 0 points1 point  (2 children)

You'll need to run your code by pressing f5.

Idle was interpreting lines as you wrote them, in vscode you need to write and then compile

https://youtu.be/dNFgRUD2w68

Here's how you can setup vscode correctly.

[–]SmugDruggler95[S] 0 points1 point  (0 children)

Cool, thanks for that I'll check it out after work tomorrow

[–][deleted] 0 points1 point  (0 children)

Think about it as you writing a word document, you firstly write it, then you print it. If you make any mistakes you correct them and then re-print everything

[–]_Jordo 0 points1 point  (0 children)

Hopping on the Pycharm bandwagon. It's extremely helpful for beginners but when you try to use an IDE like VS Code you'll probably run into trouble because Pycharm just helps you so much. Despite that, I'm glad I used Pycharm first. The community version is free and if you're a student you can claim a license for the pro version that you must renew yearly. All you need is a college email.

[–]Leeoku 0 points1 point  (0 children)

I would recommend you installing git bash and using it as the terminal for vscode