6
Contributors
10
Replies
14
Views
5 Years
Discussion Span
Last Post by syeda amna
Featured Replies
  • 1

    Hi, May be, os.system() is useful to you: [Click Here](http://docs.python.org/library/os.html#os.system) Forgive me if I am wrong. Read More

  • [See the light](http://docs.python.org/using/windows.html) with python guru Mark Hammond. Read More

  • I believe that what you are looking for is the `import` statement. If you have a Python file, say *test.py*, and wish to run the program in that source file while in the interpreter prompt, you can enter import test and, provided that the file *test.py* is in the same … Read More

  • 1

    That command is for shell/cmd.exe (WindowKey-R cmd <enter key>) not to python read-eval-print loop of interaction aka Python prompt (>>>) Read More

  • 1

    Let's say you have this program saved as test.py in folder "C:/Python27/Mytests/" # save as test.py for x in range(10): print(x) Now you can do this in the Python shell and see the output... Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", … Read More

1

I believe that what you are looking for is the import statement. If you have a Python file, say test.py, and wish to run the program in that source file while in the interpreter prompt, you can enter

import test

and, provided that the file test.py is in the same directory that you launched the Python interpreter from, you should be able to run the program, as well as access it's variables, call it's functions, etc. once it is imported.

Mind you, this is not the usual manner in which Python programs are run. It is more typical to have the .py files associated with pythonw.exe, which allows you to run the program just by double-clicking on the file. See the link Gribouillis posted for more details.

If, rather, you are looking to edit and test the program in question, you would be better off running IDLE (and simple integrated development environment that should have come with your Python distribution), which has a window for the interpreter prompt but also allows you to open separate editing windows for working on your source files. If you launch IDLE, the go to File-> Open File... and select your test.py file, it will open a window showing the source code; you can then run the program by going to Run-> Run Module in that window. IDLE takes a bit of getting used to, so you might consider a more powerful IDE such as Dr Python (very simple to learn and use, but only supports Python 2.x, and you need to install wxWindows before running it), PyPE, or Eric (much more powerful and complete, and a bit tricky to set up as you need to install both Qt4 and PyQt4 before running the installation).

Edited by Schol-R-LEA

0

I dont know what is the problem behind it. Actually i have an assignment in which i have to test from python command line.
For example i have to test python test.py -l
what does it mean.

1

That command is for shell/cmd.exe (WindowKey-R cmd <enter key>) not to python read-eval-print loop of interaction aka Python prompt (>>>)

Edited by pyTony

1

Let's say you have this program saved as test.py in folder "C:/Python27/Mytests/"

# save as test.py
for x in range(10):
    print(x)

Now you can do this in the Python shell and see the output...

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> execfile("C:/Python27/Mytests/test.py")
0
1
2
3
4
5
6
7
8
9
>>> 

In your case specify the D: drive.

Edited by vegaseat

Votes + Comments
Thank u.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.