Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics Types and Branching If, Else and Elif

I'm stuck. It seems like I get a 'Name Error' no matter what I do now.

Is there a way to get a fresh start on this Workspace? I'm not sure if I jacked the files up or something of that nature. But it seems like no matter what I try to do in the console results in a Name Error every single time. Not very adept at reading errors (yet). But to me, it almost seems as if it's no longer finding the files from the module when I try to run them.

Here's some of what I entered to show an example:

Python 3.9.0 (default, Jan 21 2021, 00:46:14)                                                                  
[GCC 5.4.0 20160609] on linux                                                                                  
Type "help", "copyright", "credits" or "license" for more information.                                         
>>> hello.py                                                                                                   
Traceback (most recent call last):                                                                             
  File "<stdin>", line 1, in <module>                                                                          
NameError: name 'hello' is not defined                                                                         
>>> hello.py                                                                                                   
Traceback (most recent call last):                                                                             
  File "<stdin>", line 1, in <module>                                                                          
NameError: name 'hello' is not defined                                                                         
>>> hello.py                                                                                                   
Traceback (most recent call last):                                                                             
  File "<stdin>", line 1, in <module>                                                                          
NameError: name 'hello' is not defined                                                                         
>>> goodbye.py                                                                                                 
Traceback (most recent call last):                                                                             
  File "<stdin>", line 1, in <module>                                                                          
NameError: name 'goodbye' is not defined                                                                       
>>> welcome.md                                                                                                 
Traceback (most recent call last):                                                                             
  File "<stdin>", line 1, in <module>                                                                          
NameError: name 'welcome' is not defined                          

Please help me out if you know what I'm doing wrong; or if there's a way I can fix it. I'm eager to learn and progress on this track. But can't and don't want to do so until I get this sorted out.

Thanks! -Scott

3 Answers

AJ Tran
STAFF
AJ Tran
Treehouse Teacher

Hi Scott Pileggi !

So in the workspace it looks like you were working in the Terminal and entered the Python Interpreter. You will know you're in "Python-land" because of the three angled brackets, >>>. You can exit the interpreter with the keyboard shortcut <control> + d or by sending the command, quit().

In the interpreter, you can import your code as Chris Freeman did demonstrate with some code snippets. This is nice if you want to "interactively" explore your program.

But for most beginners, it is more common to run your program from the command line. In your terminal, when you see the words, treehouse:~/workspace$, it means you are back on the command line. From here, you can run your script with python hello.py and you have to send that command all on one line. Then, if your program has print statements, you will see the output in the terminal.

You can totally play around and manage your workspaces too! Visit the Workspaces page to do so -- there is also a tutorial video there.

Hope this helps you, Scott! Be safe and happy coding!

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

The REPL interpreter only sees the built-in core python code by default. To access other modules they must be imported.

>>> import hello
>>> hello.some_function()

# or

>>> from hello import some_function
>>> some_function()

Post back if you need more help. Good luck!!!

Thank you! I got this sorted out but I'll definitely reach out if I need help in the future. I'm brand new but determined to get better!

Great! I figured it out! typing 'python hello.py' solved my problem. I'm brand new to this so I'm still getting familiar with what does what, what to type where, all of it really!

I'm just happy this was easily cleared up. I've been eager to keep moving forward! Hoping to be fluent in python in no time!