Q:

Can executable shell scripts be generated in python?

I am trying to create a script that installs and configures multiple programs such as phpmyadmin using a password determined by the user. To ensure the password of the user is safe, I intend to generate the shell script below using a password entered by the user, pass it to the script for output, and destroy the script once it is done running to ensure the integrity of the password. The problem is, I'm not sure how to create shell scripts within a python code.
Script:
echo phpmyadmin phpmyadmin/dbconfig-install boolean true | debconf-set-selections
echo phpmyadmin phpmyadmin/app-password-confirm password pwd | debconf-set-selections
echo phpmyadmin phpmyadmin/mysql/admin-pass password pwd| debconf-set-selections
echo phpmyadmin phpmyadmin/mysql/app-pass password pwd| debconf-set-selections
echo phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2 | debconf-set-selections
echo phpmyadmin phpmyadmin/upgrade-backup boolean true | debconf-set-selections

A:

You can generate the executable file as any other text file.
To make really executable, you either have to set executable permission on it, or call it with some interpreter like 
$ source yourscriptfile

Btw - having passwords written to files is not very safe, imagine, your cleanup code would crash and not delete the files.
Often this is resolved by setting the password to system variable and referring in your script to that variable.
Python allows executing scripts (see subprocess) and manipulating environmental variables.

