How do I open a .py file in python from a .py file in pypy?
Question: My program currently consists of 2 .py files.

I run the main part of the code in pypy (which is much faster) and then I open
a second file in python that plots my data using `matplotlib.pyplot`.

I have managed to open the using:

    
    
    subprocess.Popen(['C:\\python26\\python.exe ','main_plot.py',])
    

which opens my second file...

    
    
    import matplotlib.pyplot as pyplot
    def plot_function(NUMBER):
        '''some code that uses the argument NUMBER'''
        pyplot.figure()
        ---plot some data---
        pyplot.show()
    

However, I would like to be able to pass arguments to the `plot_function` that
opens in python. Is that possible?


Answer: Yes, the Popen constructor takes a list of length n. [See the note
here.](http://docs.python.org/2/library/subprocess.html#popen-constructor) So
just add the arguments to main_plot.py to your list:

    
    
    subprocess.Popen(['C:\\python26\\python.exe ','main_plot.py','-n',1234])
    

EDIT (to respond to your edit):

You need to modify main_plot.py to accept a command line argument to call your
function. This will do it:

    
    
    import matplotlib.pyplot as pyplot
    def plot_function(NUMBER):
        '''some code that uses the argument NUMBER'''
        pyplot.figure()
        ---plot some data---
        pyplot.show()
    
    import argparse
    if __name__=="__main__":
        argp=argparse.ArgumentParser("plot my function")
        argp.add_argument("-n","--number",type=int,default=0,required=True,help="some argument NUMBER, change type and default accordingly")
        args=argp.parse_args()
        plot_function(args.number)
    

