-2

I'd like to know what to use to write a python script from another python script. When I will execute the 1st one, the 2nd one will be created with stuff I have in the first one.

Thank you.

john
  • 1
  • 1
  • 1
    possible duplicate [link](http://stackoverflow.com/questions/16048237/pass-variable-between-python-scripts) – dlavila Jun 16 '15 at 16:40

1 Answers1

3

A python script is a normal plain text file. You can create it and write whatever you want into it exactly like you would do with a txt file.

One example is the following:

code = 'print "Hello world!"'
with open('my_script.py', 'w') as f:
    f.write(code)

Now if you execute my_script.py, it will print "Hello world!"

alec_djinn
  • 10,104
  • 8
  • 46
  • 71