-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.

1
  • 1
    possible duplicate link Commented Jun 16, 2015 at 16:40

1 Answer 1

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!"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.