I’m trying to have python recall the ‘enstring’ variable I set using the ‘crypto’ method I created so I can use it in the ‘decrypto’ method.
class encryptString():
def crypto(self, string):
enstring = base64.b64encode(string)
print enstring
def decrypto(self, enstring):
destring = base64.b64decode(enstring)
print destring
So, I want ‘crypto’ to set ‘enstring’ as the variable for the encoded string. However, when I call the variable after using the ‘crypto’ method, I get the “enstring is not defined” error.
How can I fix this?
Use
self.enstringboth times. Do the same fordestring. Don’t passenstringtodecryptoas it’ll be part ofself.This way,
enstringanddestringare instance attributes, so they’re not lost when thecryptoanddecryptomethods return.