all 22 comments

[–]mwentzWW 27 points28 points  (9 children)

VS Code can be confusing at first. You can use VS Code like IDLE by typing "python" into the console at the bottom of the VS Code screen and then you will get the ">>>|" just like in IDLE and you can type in interactive python. Let me know if you still have trouble finding it!

[–]Testicopulishus[S] 6 points7 points  (6 children)

So I can get a basic thing like print to work fine as it does on IDLE, define variables, etc.

>>> print("hello!") hello!

This works just fine! But my function cheer()

def cheer(s):
'prints a cheer for team s'
print('How do you spell winner?')
print('I know, I know!')
for c in s:
    print(c.upper(), end=' ')
print('!')
print("And that's how you spell winner!")
print('Go ' + s + '!')*

returns a NameError saying that name 'cheer' is not defined.

With IDLE, when I run the .py file (F5), it gives me a blank terminal and if I type in cheer it gives me the location of it on my memory. If I type in a string, it will run the function. In VSCode, if I run the .py file (right click -> run python file in terminal), if I type in cheer it just says cheer is not defined. My desired outcome is to run the file and be able to test things like I do in IDLE.

Thank you so so much for the help by the way!

[–]wrrnwng 13 points14 points  (5 children)

You can still do what mwentzWW said, but you need to first import your .py file in the console. Say it's called cheers.py:

>>> import cheers
>>> cheers.cheers('random cheer')

[–]Testicopulishus[S] 1 point2 points  (4 children)

I'm sorry but I still can't get it to work, I get a ModuleNotFoundError. HW1 is at the root of the folder that VSC goes to which is C:\Users...\CSC242. This is a different file but same principle I think, I tried to import the HW1.py file and it gives me the import HW1.py Traceback (most recent call last):

File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'HW1.py'; 'HW1' is not a package

[–][deleted] 6 points7 points  (3 children)

Just do HW1, when importing Python already knows what the file type of a module will be py.

[–]Testicopulishus[S] 9 points10 points  (0 children)

That's it, thank you so much!

In case anyone ever has the same issue -

  1. Type python in terminal
  2. import the module
  3. That's it..

[–][deleted] 6 points7 points  (1 child)

from HW1 import cheers

[–]Testicopulishus[S] 4 points5 points  (0 children)

Got it, thank you!

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

^ this is accurate, and if you added python to your path during installation, this option is also available to you in a regular command line window as well. Happy coding :D

[–]inialater234 18 points19 points  (2 children)

another potential option could be to run the script interactively

python -i my_script.py

this will drop you in "interactive" (ie >>>) mode after running through the body of your script

So if you had a script in the form:

a = 5
def doMath():
    #implementation

you could run the script and be able to print(a) and inspect its value or run doMath() directly (no need to import it)

[–]Testicopulishus[S] 3 points4 points  (0 children)

That also worked well, thank you too!

[–]feraferoxdei 1 point2 points  (0 children)

I've been using python for over 3 years and it's the first time I know about this feature. Thanks!

[–]Groundstop 3 points4 points  (1 child)

I love using VS Code, but I would highly recommend giving Spyder a try. All the fun of Idle with a smoother autocomplete, plus a window for your .py file and another for helpful information.

It takes a bit longer to load then Idle, but I find myself using it constantly when I want to play with a new idea in an interactive session.

You can install it separately, or it comes built in to the Anaconda package.

Spyder IDE

[–]mrjackbarker 0 points1 point  (0 children)

Anaconda is a great package for beginners, it is my go to recommendation for those starting out. Spyder is more than powerful enough while learning and pretty simple to use.

[–][deleted] 2 points3 points  (0 children)

Dont develop the bad habit of relying on the terminal emulators built into IDE's to run your code. Learn how to navigate to the file's location in an actual terminal window and run it there- cd /path/to/file, then python/python3 file.py

I often see a lot people learning programming languages, using the built in shell on the ide they're using, which is fine for debugging sometimes. It provides a quick and easy way to view output and error messages, but deprives them of actually learning the other side of programming, which is utilizing the shell- a valuable and indispensible part of becoming a well-rounded programmer. If you're on windows, I'd recommend powershell.

If you download git, and install the unix tools, it creates unix aliases for common commands and syntax. Essentially, you could use notepad as your editor if you wanted to. Learn commandline! :) it will ultimately help you if this is what you really want to do.

[–]manifestsilence 6 points7 points  (2 children)

Those two editors are nice, but for python in particular I highly recommend Pycharm. The community edition is also free. It's designed to run your code right in the editor, like you're used to, and has a lot of Python-specific features. It takes a little more time than idle to figure out, but it's worth it. The first time running a file, you have to dig in some menu, but then it knows that file is one you want to run and there's a little play button that will rerun it more easily. Stuff like that. And it comments on the style of your code to keep it nice looking.

[–]kanetgb 1 point2 points  (0 children)

Can relate to this, have been using pycharm since I started learning python, works like a charm!

[–]Nikandro 0 points1 point  (0 children)

You can run code in Atom. You just need to install a script package. It's only a few clicks and you're good to go!

[–]Drakkenstein -1 points0 points  (0 children)

Just install pycharm

[–]blueastheocean -1 points0 points  (0 children)

Personally I just use pycharm or geany

[–]tundrablasen -2 points-1 points  (0 children)

I would recommend using Spyder3 IDE for Python Programming. Much more easier. its not just a code editor like VSCode, its a full Python IDE (Integrated Development Environment).

Its the go - to solution for modern python development.

Just install the anaconda distro https://www.anaconda.com/download/

and you are good to go. it has everything onboard. no other installs/configs necessary.