0

So I am relatively new to programming and used to use Python's own "IDLE". After I run a ".py" file with IDLE, I am used to getting a python shell or a command window, I don't really know the terminological name for it, where I could play around with the objects inside the script.

For example, if I had a list A=[1,2,3] inside the program, after I run it I get a command console that says ">>" and I can say ">>A" which gives me "[1,2,3]" and I can add elements to A etc.

Now, I want to start using VS Code but I can't seem to find that particular thing. I have a terminal where I can run python code if I give the command "python" first, but It doesn't seem to effect anything inside the script.

I want to use that to see if some objects are working fine and to check their types etc. I add more lines to code after I try from there first, if that makes sense.

Sorry for really bad terminology, I really don't know the names but I can try even more if it's not clear.

Thanks a lot in advance.

2 Answers 2

1

Are you looking for the Integrated Terminal of VS Code?

Here are some ways to open the terminal:

  • Use the ⌃` keyboard shortcut with the backtick character.

  • Use the View > Terminal menu command.

  • From the Command Palette (⇧⌘P), use the View: Toggle Integrated Terminal command.

In the window that shows up, enter python and you'll get the Python shell you're looking for.

Sign up to request clarification or add additional context in comments.

4 Comments

After I write python on the terminal, I can write python code and it runs it but it doesn't see the already defined things on the script and says NameError: name 'A' is not defined for example.
You'll need to copy-paste the contents of the script into the Python shell first :) The Python shell starts afresh and does not know what's in your .py file
Ahaha is there no way for it to work like I want it? Because IDLE has it built in, after the .py file runs the shell can interpret the stuff inside the file... :( sad.
When you run a python file with python.exe on a command line, it normally runs and exits. If you add the '-i' (interactive) option, python -i xyz.py, python switches to interactive mode and prints '>>>' instead of exiting. IDLE acts the same way when one runs code from an IDLE editor. I have not used VS Code but perhaps knowing that you are looking for '-i' or an imitation thereof will help you.
1

Try using the integrated terminal inside vs code and make sure that python and pip are properly configured. Type python in the command line and make sure the terminal points to the same folder where your program file is located.

2 Comments

Ok so the program I wrote has A=[1,2,3] but after I tried this, it says: NameError: name 'A' is not defined
Xia, you need to ensure you have copy-pasted the code into the terminal or at least declared the objects before trying to access them. For example: run A = [2, 3, 4] before looking for what's inside A.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.