| | |
execute python script from shell/Interactive Window
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Aug 2005
Posts: 148
Reputation:
Solved Threads: 6
Hello,
I'm using PythonWin and I have a problem.
i don't know how to run script from Python shell Pythonwin Interactive Window).
For example I wrote this code (from tutorial):
and I save it as Script.py in Folder Atest which is in Python24
However, I have a problem to run it with command line arguments.
I can do that by choosing File->Run and then to enter arguments,
but I'd like to find out how to to run script from shell.
At first, I thought the problem is because there is no defined path to folder Atest, but I saved file in Python24 folder but problem still exists.
I have been trying to execute script.py by typing
>>> script.py and keep getting the following error:
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
NameError: name 'script' is not defined
I'm using PythonWin and I have a problem.
i don't know how to run script from Python shell Pythonwin Interactive Window).
For example I wrote this code (from tutorial):
Python Syntax (Toggle Plain Text)
import sys print 'Begining... now...' for x in sys.argv: print x
and I save it as Script.py in Folder Atest which is in Python24
However, I have a problem to run it with command line arguments.
I can do that by choosing File->Run and then to enter arguments,
but I'd like to find out how to to run script from shell.
At first, I thought the problem is because there is no defined path to folder Atest, but I saved file in Python24 folder but problem still exists.
I have been trying to execute script.py by typing
>>> script.py and keep getting the following error:
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
NameError: name 'script' is not defined
•
•
Join Date: Aug 2005
Posts: 148
Reputation:
Solved Threads: 6
•
•
•
•
Originally Posted by vegaseat
Try this:
execfile("script.py argument1 argument2")
For the moment I don't have access to Python, let me know if it works.
execfile("skripta.py arg1 arg2")
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
IOError: [Errno 2] No such file or directory: 'skripta.py arg1 arg2'
(File is named skripta.py so this isn't mistake)
I found in documentation this
"execfile(...)
execfile(filename[, globals[, locals]])
Read and execute a Python script from a file.
The globals and locals are dictionaries, defaulting to the current
globals and locals. If only globals is given, locals defaults to it."
So probably execfile doesn't support args....

Thank you vegaseat, I'm very grateful for your help.
Found this in my code library ...
Where Skripta.py contains this code ...
Python Syntax (Toggle Plain Text)
# run an external program from within Python code # subprocess.call(["program-name", "param1", "param2"]) # safer than os.system("program-name") # new in Python24 import subprocess subprocess.call(["D:/Python24/Python.exe", "Skripta.py", "arg1", "arg2"])
Python Syntax (Toggle Plain Text)
import sys import time print 'Beginning... now...' for x in sys.argv: print x time.sleep(5) # 5 seconds to look at result
May 'the Google' be with you!
•
•
Join Date: Feb 2007
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
I've tried that almost immediately after I saw that execfile() function. Unfortunately I'm getting message:
execfile("skripta.py arg1 arg2")
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
IOError: [Errno 2] No such file or directory: 'skripta.py arg1 arg2'
(File is named skripta.py so this isn't mistake)
I found in documentation this
"execfile(...)
execfile(filename[, globals[, locals]])
Read and execute a Python script from a file.
The globals and locals are dictionaries, defaulting to the current
globals and locals. If only globals is given, locals defaults to it."
So probably execfile doesn't support args....
Thank you vegaseat, I'm very grateful for your help.
I met the same problem and here is the solution that I found:
execfile(filename)
functionname(argument)
Cheers.
m.
•
•
Join Date: Oct 2007
Posts: 1
Reputation:
Solved Threads: 0
guys im still a newbie in programming I also had problem in running this small things im doing in python ,so if its possible can u plz send for me the best tutorial link to this email add grigerdrogba@webmail.co.za
cheers
cheers
![]() |
Similar Threads
- Python Error (Python)
- ssh changes the way python script behaves (Python)
- I need help with setting up a "Path"...... (Python)
Other Threads in the Python Forum
- Previous Thread: Cannot get Gasp to work...Any suggestions?
- Next Thread: need some help!!!
Views: 48393 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied address ansi backend beginner changecolor class code conversion coordinates copy curves customdialog dan08 dictionary directory dynamic edit examples excel feet file float font format ftp function generator getvalue gui halp homework i/o images import info input ip java line linux list lists loop mouse mysql newb number numbers output panel parsing path port prime print program programming projects py2exe pygame pyqt python queue random rational recursion recursive schedule screensaverloopinactive scrolledtext searchingfile server ssh stamp statictext string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial type ubuntu unicode url urllib urllib2 variable whileloop windows write wxpython






