calling python script from another script
Question: i'm trying to get simple python script to call another script, just in order
to understand better how it's working. The 'main' code goes like this:

    
    
    #!/usr/bin/python
    import subprocess
    subprocess.call('kvadrat.py')
    

and the script it calls - `kvadrat.py`:

    
    
    #!/usr/bin/python
    def kvadriranje(x):
        kvadrat = x * x
        return kvadrat
    
    print kvadriranje(5)
    

Called script works on its own, but when called through 'main' script error
occurs:

    
    
    Traceback (most recent call last):
      File "/Users/user/Desktop/Python/General Test.py", line 5, in <module>
        subprocess.call('kvadrat.py')
      File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 444, in call
      File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 595, in __init__
      File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1106, in _execute_child
    OSError: [Errno 2] No such file or directory
    

Obviously something's wrong, but being a beginner don't see what.


Answer: Have you tried:

    
    
    from subprocess import call
    call(["python","kvadrat.py"]) #if in same directory, else get abs path
    

You should also check if your file is there:

    
    
    import os
    print os.path.exists('kvadrat.py')
    

