RSS Forums RSS

executing scripts via command line

Please support our Python advertiser: Programming Forums
Reply
Posts: 2
Reputation: payne_99 is an unknown quantity at this point 
Solved Threads: 0
payne_99 payne_99 is offline Offline
Newbie Poster

executing scripts via command line

  #1  
Nov 21st, 2008
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?

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!
AddThis Social Bookmark Button
Reply With Quote  
Posts: 521
Reputation: Gribouillis will become famous soon enough Gribouillis will become famous soon enough 
Solved Threads: 92
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Posting Pro

Re: executing scripts via command line

  #2  
Nov 21st, 2008
The syntax error is somewhere in your script. Can you post the script (or attach it) ?
Reply With Quote  
Posts: 2
Reputation: payne_99 is an unknown quantity at this point 
Solved Threads: 0
payne_99 payne_99 is offline Offline
Newbie Poster

Re: executing scripts via command line

  #3  
Nov 21st, 2008
Ah, I see. So the actual command I was trying to execute was

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:

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.
Reply With Quote  
Posts: 655
Reputation: paulthom12345 will become famous soon enough paulthom12345 will become famous soon enough 
Solved Threads: 91
paulthom12345's Avatar
paulthom12345 paulthom12345 is offline Offline
Practically a Master Poster

Re: executing scripts via command line

  #4  
Nov 21st, 2008
Your problem is that sys.argv is what you supply on the command line after starting the script. So you would go
  1. python mycode.py arg1 arg2
For yours to work you need at least 2 arguments for there to be sys.argv[1]
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the Python Forum
Views: 469 | Replies: 3 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:36 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC