So I'm new to python, although not terribly new to programming. I am going through some tutorials, but am having some trouble.

I am trying to execute a program from the python shell (using Python 3.1). Right now, I have the >>> prompt. I can't seem to get any program to execute from this prompt. If I put my program into a new window and then click "Run Module," it works. But I can't get it to execute from the >>> prompt in the shell.

I have tried these variations (note - my module name is humansize.py and this is stored in a folder located at C:/Python31/Examples):

>>> import sys
>>> humansize
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
humansize
NameError: name 'humansize' is not defined
>>> humansize.py
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
humansize.py
NameError: name 'humansize' is not defined
>>> import sys
>>> sys.path

>>> sys
<module 'sys' (built-in)>
>>> sys.path.insert(0,'Python31/Examples')
>>> sys
<module 'sys' (built-in)>
>>> sys.path

>>> execfile(humansize.py)
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
execfile(humansize.py)
NameError: name 'execfile' is not defined
>>> execfile(humansize)
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
execfile(humansize)
NameError: name 'execfile' is not defined
>>> execfile('humansize.py')
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
execfile('humansize.py')
NameError: name 'execfile' is not defined
>>> execfile('humansize')
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
execfile('humansize')
NameError: name 'execfile' is not defined
>>> import sys
>>> C:\Python31\python.exe humansize.py
SyntaxError: invalid syntax
>>> python.eye humansize.py
SyntaxError: invalid syntax
>>>


So what am I doing wrong??????

import humanize ?

Thanks for the response, but still no luck.

I'm on windows so ordi's response won't work as it is for Linux

I tried import humansize but that doesn't allow me to RUN the file from the shell. It just imports it. I don't understand why this is so difficult... I *have* to be missing something obvious???

I just want to execute humansize.py from the >>> prompt in the shell (interactive IDLE). How do I do that?

Do help(humansize) or dir(humansize) and call the main function of the file. Why can you not open the file normally and run it from editor side by F5. Final testing is better done without IDE from CMD prompt or launch the program by double clicking the file. I currently like to work in ContextEditor where I have defined function keys to launch the program with 2.6, 2.7 and 3.2. Sometimes I am missing the code completion and help features of Idle and run it side by side with the text editor.
You might like to use Ipython for better command line.

humansize.py from the >>> prompt in the shell (interactive IDLE). How do I do that?

You dont do that because it wrong.
To run a script.
From cmd python humansize.py or as posted by tony by using File->new window then F5(run) .
If you want to use humansize.py in IDLE you have to import it.
How to import and using a script look at this post.
http://www.daniweb.com/forums/thread322120.html

A good editor like pyscripter make it easy,it has run button.
http://code.google.com/p/pyscripter/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.