Friday 15 June 2012

How to run a python script from IDLE interactive shell? -


How do I run a Python script from the IDE Interactive Shell?

The following triggers an error:

  & gt; & Gt; & Gt; Python helloworld.py syntax error: invalid syntax    

Built-in function:

  execfile ('helloworld.py')   

This can not normally be called with logic. But here is a workaround:

  import sys sys.argv = ['helloworld.py', 'arg'] # argv [0] still the script name execfile ('helloworld.py' ) Deprecated since 2.6:    
  Import os.popen ('python helloworld.py') #   
< P> Just to run the program os.popen ('python helloworld.py'). Read () # You also get stdout

with argument:

  os Advance use:      Import (python helloworld.py arg)   Subprocess subprances Cole (['Python', 'Hairlourldged']) # Bus Programs Upprocessor.   

With the argument:

  Sub process . (['Python', 'helloworld.py', 'Arg'])   

Read the docs for details: -)


The original Helloworld.py :

  has been tested with the import system if len (sys.argv) & Gt; 1: print (sys.argv [1])    

No comments:

Post a Comment