There is definitely no need for two classes to do something like this. All you have to do is create another method in put_data.py called init _ () and then do something according to the lines:
x = raw_input('text1:') y = getpass.getpass('pass1:') z = getpass.getpass('pass2:')
Then you can just use pexpect for the rest:
child = pexpect.spawn(x, timeout=180) while True: x = child.expect(["(current)", "new", "changed", pexpect.EOF, pexpect.TIMEOUT]) if x is 0: child.sendline(y) time.sleep(1) if x is 1: child.sendline(z) time.sleep(1) if x is 2: print "success!" break
TA-dah! Of course, you are likely to get a ton of errors with such code. You should always use the provided methods, if you are using linux, it is easier to run os.system ("passwd") and let the shell take care of the rest. Also, if at all possible, always avoid using getpass, it is a funky outdated method and can damage things along the way.
source share