Can I run a python file within another python file?
Question: > **Possible Duplicate:**  
>  [Run a python script from another python script, passing in
> args](http://stackoverflow.com/questions/3781851/run-a-python-script-from-
> another-python-script-passing-in-args)

Suppose I have script2.py that returns a int value.

Is it possible to run only script.py on my shell and within script.py gets in
some way the int value returned by script2.py according to parameters I passed
to script.py?


Answer: Yes it's possible. That's what modules are used for :).

First you have to put the method that you use in script2.py into a function.
I'll use the same example as the person above me has used (because it's a good
example :p).

    
    
    def myFunction(a, b):
        return a + b
    

Now on your script.py, you'll want to put:

    
    
    import script2
    

at the top. This will only work if both files are in the same directory.

To use the function, you would type:

    
    
    # Adding up two numbers
    script2.myFunction(1, 2)
    

and that should return 3.

