| | |
executing scripts via command line
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2008
Posts: 2
Reputation:
Solved Threads: 0
Hello!
I'm trying to execute a simple script in the command line, and for some reason, it's not working. Shouldn't it be as simple as this?
And yet when I try that, I get "Syntax Error: invalid syntax"
I've googled around, read through the docs--I have a feeling that this is probably something silly/small. Any help?
Thanks!
I'm trying to execute a simple script in the command line, and for some reason, it's not working. Shouldn't it be as simple as this?
Python Syntax (Toggle Plain Text)
python myscript.py
And yet when I try that, I get "Syntax Error: invalid syntax"
I've googled around, read through the docs--I have a feeling that this is probably something silly/small. Any help?
Thanks!
•
•
Join Date: Nov 2008
Posts: 2
Reputation:
Solved Threads: 0
Ah, I see. So the actual command I was trying to execute was
I checked controller.py, and got an error message:
Traceback (most recent call last):
File "C:\Users\p\controller.py", line 3, in <module>
exec "from " + sys.argv[1] + " import *"
IndexError: list index out of range
Here's the script:
There are other files (the "tichu" file it's importing from); let me know if you need to see more.
Python Syntax (Toggle Plain Text)
python controller.py
I checked controller.py, and got an error message:
Traceback (most recent call last):
File "C:\Users\p\controller.py", line 3, in <module>
exec "from " + sys.argv[1] + " import *"
IndexError: list index out of range
Here's the script:
Python Syntax (Toggle Plain Text)
import sys from tichu import * exec "from " + sys.argv[1] + " import *" def exampleFeatureFunction(hand): fv=[0, 0, 0] fv[0]=1 if (hand[DRAGON]>0): fv[1]=1.0 if (hand[PHOENIX]>0): fv[2]=1.0 return fv def alwaysSayNo(hand, model): return False if __name__=="__main__": if (sys.argv[3]=="baseline"): evaluate(sys.argv[2], None, alwaysSayNo) elif (sys.argv[3]): evaluate(sys.argv[2], sys.argv[3], eval(sys.argv[4]))
There are other files (the "tichu" file it's importing from); let me know if you need to see more.
Your problem is that sys.argv is what you supply on the command line after starting the script. So you would go
For yours to work you need at least 2 arguments for there to be sys.argv[1]
python Syntax (Toggle Plain Text)
python mycode.py arg1 arg2
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
![]() |
Similar Threads
- libgpod3 + gtkpod (*nix Software)
- blank pop-ups (Viruses, Spyware and other Nasties)
- Hello from Ubuntu (Geeks' Lounge)
Other Threads in the Python Forum
- Previous Thread: PythonFight
- Next Thread: Passing varyables through a text file
Views: 610 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Python
advanced assignment beginner bits bluetooth chmod cmd code convert count csv cursor data decimals dictionary dynamic dynamically enter examples excel external file float format frange ftp function gnu gui heads homework import input jaunty java leftmouse line linux list lists loan loop module mouse multiple newb number numbers output parsing path port prime program programming projects push py2exe pygame pygtk pyopengl pyqt python random raw_input recursion recursive scrolledtext slicenotation software ssh stderr string strings table tennis terminal text thread threading time tkinter tlapse tooltip tricks tuple tutorial ubuntu unicode update urllib urllib2 variable variables ventrilo web webservice windows wx.wizard wxpython





