-
Notifications
You must be signed in to change notification settings - Fork 479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello world! from Command Prompt Error #12
Comments
Thank you for letting me know. I believe your system recognizes .py files as executable files, and knows where to find the Python interpreter when it needs to run a .py file. |
Yes, was a little bit frustrating when I can’t even execute the first “Hello world” assignment. Almost grabbed me a book of py for dummies. This is for those who shall share my similar faith and to never give up 😁 |
Are you saying this worked: > hello_world But this did not: > python hello_world.py Or was it this? > python hello_world |
The second one. |
Okay, that's interesting. Are you sure you saved your file as For a simple script like hello world, the .py extension isn't always needed: ~/test_code/py_ext_tester$ ls -alh
-rw-r--r-- 1 eric staff 23B May 3 08:31 hello
-rw-r--r-- 1 eric staff 23B May 3 08:31 hello.py
-rw-r--r-- 1 eric staff 23B May 3 08:34 hello.txt
~/test_code/py_ext_tester$ python hello.py
Hello world!
~/test_code/py_ext_tester$ python hello.txt
Hello world!
~/test_code/py_ext_tester$ python hello
Hello world! This example is on macOS, but the same thing should apply to Windows. It gets confusing because file browsers such as Windows Explorer used to show all file extensions by default. Now they tend to hide extensions unless you configure them to show all extensions. So you might see You can check the filename definitively in the terminal with the |
That is a good point. I’ll check the file name when i get home later and share the output. I remember saving it as hello_world.py from the vs window though it dropped the .py when it went windows to save as i recall but i did not put much thought to that as my default does not show the file extensions. |
C:\Users\marop\OneDrive\Desktop\python_work>dir Directory of C:\Users\marop\OneDrive\Desktop\python_work 05/03/2024 04:39 AM .05/03/2024 04:39 AM .. 05/01/2024 05:15 PM .vscode 05/01/2024 09:49 PM 399 bicycles 05/03/2024 04:39 AM 1,235 Cars 05/01/2024 06:05 PM 182 hello_world 05/03/2024 05:20 AM 589 lapamilya.py 05/01/2024 06:12 PM 172 mensahe.py 05/01/2024 09:22 PM 433 name.py 05/01/2024 07:04 PM 249 name_cases.py 05/01/2024 07:10 PM 392 name_quotes 05/01/2024 09:21 PM 223 numbers 05/01/2024 09:32 PM 13 Zen_Python 10 File(s) 3,887 bytes 3 Dir(s) 422,718,844,928 bytes free C:\Users\marop\OneDrive\Desktop\python_work> |
You're right. Apparently, I saved it as hello_world, and not hello_world.py |
I'm glad we got that sorted. :) I see I'll admit I had a file called numbers.py in the first edition of PCC, and it caused some issues for some readers. 🤦 |
Eric, just started on your book Python Crash Course 3rd Edition.
On page 12 about getting Hello world! to work on Windows Command Prompt, when inside the correct directory, I only needed to type the command hello_world, instead of hello_world.py.
The text was updated successfully, but these errors were encountered: