Newbie Python Question

MDS1005

Baseband Member
Messages
29
I've seen the question asked before on other sites, but never saw an acceptable answer. Just starting out in Python (like JUST as in 5 minutes ago). Running Python 3.0 on Windows XP. Now, the Hello World program. Here is exactly what i type in IDLE 3.0....:

>>> #!/usr/bin/python
>>> #Filename: helloworld.py
>>>

>>>print('Hello World')

Now, If I hit enter from here directly, I get the following line giving me the output of:

Hello World

>>>

So, at this point, I am assuming the program is running correctly. The problem comes next. From here, I save the file as helloworld.py...... I close IDLE 3.0. Re-open it. I then open the helloworld.py file, which appears in a new IDLE window. I then go to Run, and then Run Module. Then, all that happens is a warning box appears with "invalid syntax." WHY DOES THIS KEEP HAPPENING?!

Just a note that probably isnt important. The only way I can get the RUN menu to appear in IDLE is to close IDLE after the program is saved, reopen IDLE, File then Open, which opens the program in a new IDLE window (kinda pointless dont you think?). At this point, the newly opened IDLE window displays the RUN menu at the top.



Well, this darn message board keeps Automerging my post when I try to reply to this, so be aware of the following:

Answered my own question here. Problem has been solved. But this leads me to a new question. IDLE is the Python Shell obviously. When selecting File>Open New Window.... is the New Window the only place that programs should be typed in? Is the shell just for displaying output? Am I even asking an accurate question here or am I just totally missing some obvious point?
 
Thank you Spec. I now feel like less of a Python noob for knowing that Windows CAN open a .py file, albeit in DOS or in IDLE.... sorry, just taking cheap shots in good fun :D .
 
No, as my understanding goes, Python is NOT a compiled language, rather Python source code is translated into bytecode, which is run by a virtual machine similar to how Java works..... anyone out there more familiar with Python that can tell me if this is correct and answer my original question as well?
 
yeah im pretty confused, thought you were just trying to open a compiled .py file..
 
No, as my understanding goes, Python is NOT a compiled language, rather Python source code is translated into bytecode, which is run by a virtual machine similar to how Java works..... anyone out there more familiar with Python that can tell me if this is correct and answer my original question as well?

Python is typically a scripting language. It is not translated the same as Java because Java requires a compiler (ie. JDK) to build an executable file. Python is an interpreted language. I don't know how to explain it simply, but the code is analyzed and instructions are then formulated at run-time (i guess that's simply put right?).

As far as your problem goes...i don't have much to comment on as far as a solution but what i will oppose is your decision to use Windows as your programming environment.


edit - hold on a second. When you use "#!/usr/bin/python" are you sure that this is correct? I know that is the directory to use under Linux but for windows that's probably different. Although that doesn't explain why it worked the first time you ran the program so idk. Just pointed it out for curiosity.
 
Back
Top Bottom