Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 01-21-2009, 11:32 PM   #1
Baseband Member
 
Join Date: Jun 2008
Posts: 29
Default Newbie Python Question

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?
__________________

MDS1005 is offline   Reply With Quote
Old 01-22-2009, 01:20 AM   #2
Fully Optimized
 
Spec's Avatar
 
Join Date: Aug 2005
Posts: 1,641
Default Re: Newbie Python Question

well..windows cant open .py files i think.
__________________

__________________
Thermaltake ARMOR/ mATX intelG33 Motherboard/4gb G.SKILL High Gaming Performance ddr2-1200/Radeon 3870 1gb edition/850w Thermaltake superduty psu

PokerDegenerate: Don't listen to these guys, I like the IDE makes it look vintage like a 68 Camaro SS...
Spec is offline   Reply With Quote
Old 01-22-2009, 02:15 AM   #3
Baseband Member
 
Join Date: Jun 2008
Posts: 29
Default Re: Newbie Python Question

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 .
MDS1005 is offline   Reply With Quote
Old 01-22-2009, 04:34 PM   #4
Guru
 
JogaBonito1502's Avatar
 
Join Date: Jan 2008
Location: U.S.
Posts: 7,841
Default Re: Newbie Python Question

Python is not a compile language as far as I know.
JogaBonito1502 is offline   Reply With Quote
Old 01-22-2009, 05:24 PM   #5
Baseband Member
 
Join Date: Jun 2008
Posts: 29
Default Re: Newbie Python Question

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?
MDS1005 is offline   Reply With Quote
Old 01-22-2009, 10:05 PM   #6
Fully Optimized
 
Spec's Avatar
 
Join Date: Aug 2005
Posts: 1,641
Default Re: Newbie Python Question

yeah im pretty confused, thought you were just trying to open a compiled .py file..
__________________
Thermaltake ARMOR/ mATX intelG33 Motherboard/4gb G.SKILL High Gaming Performance ddr2-1200/Radeon 3870 1gb edition/850w Thermaltake superduty psu

PokerDegenerate: Don't listen to these guys, I like the IDE makes it look vintage like a 68 Camaro SS...
Spec is offline   Reply With Quote
Old 01-22-2009, 10:57 PM   #7
Fully Optimized
 
Š88's Avatar
 
Join Date: May 2005
Posts: 4,775
Send a message via MSN to Š88
Default Re: Newbie Python Question

Quote:
Originally Posted by MDS1005 View Post
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.
__________________

__________________
Killing under the cloak of war is no different than murder

Kein Alkohol ist auch keine Lösung!
Š88 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 10:49 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0